Class: ImportDocumentJob

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

Overview

ImportDocumentJob class

Instance Method Summary collapse

Instance Method Details

#perform(import_document) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'app/jobs/import_document_job.rb', line 7

def perform(import_document)
  document = Document.find_or_create_by(friendlier_id: import_document.friendlier_id)

  # Set the geom
  document.set_geometry

  if document.update(import_document.to_hash)
    import_document.state_machine.transition_to!(:success)
  else
    import_document.state_machine.transition_to!(:failed, "Failed - #{document.errors.inspect}")
  end
rescue => e
  logger.debug("Error: #{e}")
  import_document.state_machine.transition_to!(:failed, "Error - #{e.inspect}")
end