Class: BulkActionRunDocumentJob

Inherits:
ApplicationJob
  • Object
show all
Defined in:
app/jobs/bulk_action_run_document_job.rb

Overview

BulkActionRunDocumentJob

Instance Method Summary collapse

Instance Method Details

#perform(action, doc, field_name, field_value) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
# File 'app/jobs/bulk_action_run_document_job.rb', line 7

def perform(action, doc, field_name, field_value)
  case action
  when :update_publication_status
    update_publication_status(doc, field_value)
  when :update_delete
    update_delete(doc, field_value)
  # @TODO: Field Level changes
  else
    logger.debug("@TODO - #{field_name} => #{field_value}")
  end
end

#update_delete(doc, field_value) ⇒ Object



31
32
33
34
35
36
37
38
39
40
41
# File 'app/jobs/bulk_action_run_document_job.rb', line 31

def update_delete(doc, field_value)
  document = Document.find_by!(friendlier_id: doc.friendlier_id)

  logger.debug("Update Delete - #{document.friendlier_id} => #{field_value}")

  if document.destroy
    doc.state_machine.transition_to!(:success)
  else
    doc.state_machine.transition_to!(:failed)
  end
end

#update_publication_status(doc, field_value) ⇒ Object



19
20
21
22
23
24
25
26
27
28
29
# File 'app/jobs/bulk_action_run_document_job.rb', line 19

def update_publication_status(doc, field_value)
  document = Document.find_by!(friendlier_id: doc.friendlier_id)

  logger.debug("Update PubStatus - #{document.friendlier_id} => #{field_value}")

  if document.update!(publication_state: field_value.to_sym)
    doc.state_machine.transition_to!(:success)
  else
    doc.state_machine.transition_to!(:failed)
  end
end