carrierwave_backgrounder
carrierwave_backgrounder copied to clipboard
Callback when finished processing
Hey I currently use store_in_background. I need a callback which I can call as soon as all versions of a photo are created.
What's the best way to do this?
Regards, Gambo
What backend are you using?
I'm using sidekiq with redis
I am marking this as a feature request. I will look into some solutions when I get a chance.
Thanks.
+1 on this; thinking about implementing a before_process_filter and after_process_filter
+1
+1
+1
+1
+1
+1
I will try and get this pushed this week... Thanks for all the feedback.
I don't need it anymore. I have a seperate app which will upload the original file to my store and enqueues a job to sidekiq.
This worker will use model.remote_photo_url
and model.save
which has the effect of the photos being processed in background.
+1 This would be totally useful.
+1
https://github.com/mdurn/carrierwave_backgrounder/commit/01289a1136b6f93b21eaf1733249b909ad06f156
Here's an initial pass at getting the callbacks working. Specs have been added and are passing. I have not manually tested this out, though, so it would be great if somebody could try it out.
NOTE: This also comes with a change to the parameters for the "process_in_background" and "store_in_background" methods.
process_in_background now looks like this:
def process_in_background(column, options={})
The parameters are the same for store_in_background. The possible options are:
- worker
- after_store (a symbol for the callback method in your model).
Example1:
process_in_background(column, worker: ::CarrierWave::Workers::ProcessAsset)
Example2:
store_in_background(column, after_store: :do_something)
If no worker is provided, the default worker for ProcessAsset or StoreAsset is used (as it did before). Callbacks only apply when using the default workers.
+1
+1
I have pulled in @mdurn's branch into branch https://github.com/lardawge/carrierwave_backgrounder/tree/add_callback_for_after_process and tested it. There was one fix that was needed but it is currently working with a custom worker. Have yet to test it with a callback.
+1
If you need this feature and are unwilling to wait, the workaround is to create custom worker. Mine looks like this:
class StreamUploadWorker < ::CarrierWave::Workers::ProcessAsset
def perform(*args)
set_args(*args) if args.present?
video = constantized_resource.find id
run_callback video, :before_upload
super(*args)
run_callback video, :after_upload_success
rescue
run_callback video, :after_upload_failure
Rails.logger.tagged 'StreamUploadWorker' do
Rails.logger.error "Error during uploading: #{$!.message}"
$!.backtrace.each { |line| Rails.logger.error line }
end
end
def run_callback(video, callback)
if video.respond_to?(callback)
Rails.logger.debug "Running callback: #{callback} for Video #{video.id}"
video.send(callback)
else
Rails.logger.debug "Unable to run callback: #{callback} for Video #{video.id}"
end
end
end
+1
+1