app/jobs/cas/images/promote_job.rb in cas-cms-1.0.0.alpha1 vs app/jobs/cas/images/promote_job.rb in cas-cms-1.0.0.alpha2
- old
+ new
@@ -1,11 +1,20 @@
module Cas
module Images
class PromoteJob
- include ::Sidekiq::Worker
- def perform(data)
- ::Shrine::Attacher.promote(data)
+ include Sidekiq::Worker
+
+ 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
end
end
end