carrierwave_backgrounder icon indicating copy to clipboard operation
carrierwave_backgrounder copied to clipboard

Callback when finished processing

Open heygambo opened this issue 11 years ago • 23 comments

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

heygambo avatar May 23 '13 00:05 heygambo

What backend are you using?

lardawge avatar May 23 '13 02:05 lardawge

I'm using sidekiq with redis

heygambo avatar May 23 '13 21:05 heygambo

I am marking this as a feature request. I will look into some solutions when I get a chance.

lardawge avatar May 24 '13 20:05 lardawge

Thanks.

heygambo avatar May 25 '13 13:05 heygambo

+1 on this; thinking about implementing a before_process_filter and after_process_filter

korbin avatar Jun 11 '13 23:06 korbin

+1

ghost avatar Jul 10 '13 01:07 ghost

+1

heygambo avatar Jul 15 '13 12:07 heygambo

+1

juanm avatar Aug 31 '13 03:08 juanm

+1

ryana avatar Sep 21 '13 04:09 ryana

+1

ipatovanton avatar Dec 16 '13 23:12 ipatovanton

+1

ivanzotov avatar Jan 13 '14 05:01 ivanzotov

I will try and get this pushed this week... Thanks for all the feedback.

lardawge avatar Jan 13 '14 17:01 lardawge

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.

heygambo avatar Jan 14 '14 13:01 heygambo

+1 This would be totally useful.

lephyrius avatar Jun 26 '14 16:06 lephyrius

+1

ghost avatar Jun 29 '14 14:06 ghost

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.

mdurn avatar Jul 03 '14 23:07 mdurn

+1

sanderbrauwers avatar Jul 04 '14 06:07 sanderbrauwers

+1

krazyjakee avatar Jul 04 '14 19:07 krazyjakee

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.

lardawge avatar Jul 05 '14 02:07 lardawge

+1

sergiopantoja avatar Aug 10 '14 01:08 sergiopantoja

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

d4rky-pl avatar Sep 04 '14 11:09 d4rky-pl

+1

jaleszek avatar Oct 02 '14 19:10 jaleszek

+1

jschroeder9000 avatar Dec 14 '15 18:12 jschroeder9000