Class: GeoblacklightAdmin::StoreImageJob

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

Instance Method Summary collapse

Instance Method Details

#perform(solr_document_id, bad_id = nil, queue = :default) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'app/jobs/geoblacklight_admin/store_image_job.rb', line 9

def perform(solr_document_id, bad_id = nil, queue = :default)
  # Find the document
  document = Document.find_by_friendlier_id(solr_document_id)

  # Delete thumbnail if already present
  if document&.thumbnail&.present?
    document.thumbnail.destroy!
  end

  # Statesman
   = {}
  ["solr_doc_id"] = solr_document_id
  document.thumbnail_state_machine.transition_to!(:queued, )

  # Crawl politely
  sleep(rand(1..5))

  # Store the image
  GeoblacklightAdmin::ImageService.new(document).store
  BulkActionDocument.find(bad_id).state_machine.transition_to!(:success) if bad_id.present?
end