Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Callback when finished processing #139

Open
heygambo opened this issue May 23, 2013 · 23 comments
Open

Callback when finished processing #139

heygambo opened this issue May 23, 2013 · 23 comments

Comments

@heygambo
Copy link

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

@lardawge
Copy link
Owner

What backend are you using?

@heygambo
Copy link
Author

I'm using sidekiq with redis

@lardawge
Copy link
Owner

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

@heygambo
Copy link
Author

Thanks.

@korbin
Copy link

korbin commented Jun 11, 2013

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

@ghost
Copy link

ghost commented Jul 10, 2013

+1

5 similar comments
@heygambo
Copy link
Author

+1

@juanm
Copy link

juanm commented Aug 31, 2013

+1

@ryana
Copy link

ryana commented Sep 21, 2013

+1

@ipatovanton
Copy link

+1

@ivanzotov
Copy link

+1

@lardawge
Copy link
Owner

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

@heygambo
Copy link
Author

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.

@lephyrius
Copy link

+1 This would be totally useful.

@ghost
Copy link

ghost commented Jun 29, 2014

+1

mdurn added a commit to mdurn/carrierwave_backgrounder that referenced this issue Jul 3, 2014
@mdurn
Copy link

mdurn commented Jul 3, 2014

mdurn@01289a1

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.

@sanderbrauwers
Copy link

+1

1 similar comment
@krazyjakee
Copy link

+1

@lardawge
Copy link
Owner

lardawge commented Jul 5, 2014

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.

@sergiopantoja
Copy link

+1

@d4rky-pl
Copy link

d4rky-pl commented Sep 4, 2014

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

@jaleszek
Copy link

jaleszek commented Oct 2, 2014

+1

1 similar comment
@jschroeder9000
Copy link

+1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests