Class: GeoblacklightAdmin::StoreImageJob
- Inherits:
-
ApplicationJob
- Object
- ApplicationJob
- GeoblacklightAdmin::StoreImageJob
- Defined in:
- app/jobs/geoblacklight_admin/store_image_job.rb
Overview
StoreImageJob is responsible for handling the storage of images associated with a Solr document. It manages the lifecycle of the image storage process, including state transitions and error handling.
Instance Method Summary collapse
-
#perform(solr_document_id, bad_id = nil, queue = :default) ⇒ Object
Performs the job to store an image for a given Solr document.
Instance Method Details
#perform(solr_document_id, bad_id = nil, queue = :default) ⇒ Object
Performs the job to store an image for a given Solr document.
This method:
-
Finds the document by its friendlier ID.
-
Deletes any existing thumbnail.
-
Transitions the document’s thumbnail state to ‘queued’.
-
Waits for a random period to ensure polite crawling.
-
Stores the image using the ImageService.
-
Transitions the BulkActionDocument state to ‘success’ if a bad_id is provided.
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'app/jobs/geoblacklight_admin/store_image_job.rb', line 31 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 |