Skip to content
This repository has been archived by the owner on Oct 5, 2018. It is now read-only.

Getting a callback when processing is done #176

Open
eduardm opened this issue Apr 28, 2016 · 2 comments
Open

Getting a callback when processing is done #176

eduardm opened this issue Apr 28, 2016 · 2 comments

Comments

@eduardm
Copy link

eduardm commented Apr 28, 2016

I am running a video processing engine with Paperclip and Delayed_paperclip gems.

Everything works fine, but I need to trigger some things when processing is done (sending emails, copy some files somewhere else, etc). Problem is that I do not know when is ready.

I know that there is a column in DB media_processing that gets updated when the processing is done, but to use that, I have to use another table and store there any video when processing is starting, then to keep pooling the db to see which one got processing status changed.

I tried after_processing in paperclip, after_update in video model, nothing works.

My question is: How to set a callback to execute some code when processing is done.

@rafaelmotta
Copy link

+1

@bdewater
Copy link

bdewater commented Oct 3, 2016

I have a similar use case to yours. Both callbacks provided by Paperclip (after_processing :enqueue_upload and after_foo_processing :enqueue_upload) work for me to enqueue another job. This makes sense because DelayedPaperclip::ProcessJob ultimately calls Paperclip's save method (via reprocess!).

The gotcha for me was that I am running my background processor (Que) in a separate process so I needed to stop en start it every time I made changes that I wanted to test. Afaik so far only Sidekiq has adopted the new code reloading mechanism in Rails 5 to hot reload job classes for every file change.

This is what works for me on Paperclip 5.1.0 and DelayedPaperclip 3.0.1:

# models/foo_request.rb
class FooRequest < ActiveRecord::Base
  ACCEPTED_CONTENT_TYPES = %w(application/pdf image/jpeg image/tiff)

  has_attached_file :foo,
                    styles: { export: { format: 'tiff' } },
                    processors: [:foo]
  validates_attachment_content_type :foo, content_type: ACCEPTED_CONTENT_TYPES
  validates_attachment_file_name :foo, matches: [/(pdf|jpe?g|tiff)\Z/i]
  process_in_background :foo, queue: ''

  # validations omitted

  after_post_process :queue_upload

  # other methods omitted

  def queue_upload
    FooUploadJob.perform_later(self)
  end
end

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

No branches or pull requests

3 participants