Class: Cas::Images::PromoteJob

Inherits:
Object
  • Object
show all
Includes:
Sidekiq::Worker
Defined in:
app/jobs/cas/images/promote_job.rb

Instance Method Summary collapse

Instance Method Details

#perform(attacher_class, record_class, record_id, name, file_data) ⇒ Object



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

def perform(attacher_class, record_class, record_id, name, file_data)
  attacher_class = Object.const_get(attacher_class)
  record         = Object.const_get(record_class).find(record_id) # if using Active Record

  attacher = attacher_class.retrieve(model: record, name: name, file: file_data)
  attacher.create_derivatives # call derivatives processor 
  attacher.atomic_promote
rescue Shrine::AttachmentChanged, ActiveRecord::RecordNotFound => e
  Rails.logger.info e.inspect
  # attachment has changed or record has been deleted, nothing to do
end