0
votes

I am trying to run a delayed job on some image processing and having some issues.

In the create action, I first created a new instance without the image attribute so model values are available in the uploader. Then the background job is called to perform the image upload/processing.

def create
  @photo = Photo.new(photo_params.except("image"))
  UploadsWorker.perform_async(@photo.id)
  # @photo.image = photo_params.delay.delete("image")
  if @photo.save
    flash[:notice] = "Your new photograph is being processed."
    redirect_to @photo
 else
   flash[:notice] =  "Check the fields marked with an orange flag."
   render 'new'
 end

end

By moving the image call into the Worker class, I dont think the params hash is now available. The page loads with just a default image set in the uploader, but a new thumbnail never appears seeing that the processing and versioning never took place.

class UploadsWorker
  include Sidekiq::Worker
  sidekiq_options retry: false

  def perform(photo_id)
    photo = Photo.find(photo_id)
    photo.image = photo_params.delay.delete("image")
 end

end

---If i comment all the code in the perform method is still get the error.

And here is some log output from Sidekiq:

2015-03-15T02:26:02.183Z 18151 TID-ovz04wazo WARN: {"retry"=>false, "queue"=>"default", "class"=>"UploadsWorker", "args"=>[nil], "jid"=>"aa64ed564c31d1a7035ce9f2", "enqueued_at"=>1426386362.175436}
2015-03-15T02:26:02.184Z 18151 TID-ovz04wazo WARN: uninitialized constant UploadsWorker
2015-03-15T02:26:02.184Z 18151 TID-ovz04wazo WARN: /Users/jhorsch/.rvm/gems/ruby-2.0.0-p247/gems/activesupport-4.0.2/lib/active_support/inflector/methods.rb:226:in `const_get'
/Users/jhorsch/.rvm/gems/ruby-2.0.0-p247/gems/activesupport-4.0.2/lib/active_support/inflector/methods.rb:226:in `block in constantize'
/Users/jhorsch/.rvm/gems/ruby-2.0.0-p247/gems/activesupport-4.0.2/lib/active_support/inflector/methods.rb:224:in `each'
/Users/jhorsch/.rvm/gems/ruby-2.0.0-p247/gems/activesupport-4.0.2/lib/active_support/inflector/methods.rb:224:in `inject'
/Users/jhorsch/.rvm/gems/ruby-2.0.0-p247/gems/activesupport-4.0.2/lib/active_support/inflector/methods.rb:224:in `constantize'
/Users/jhorsch/.rvm/gems/ruby-2.0.0-p247/gems/activesupport-4.0.2/lib/active_support/core_ext/string/inflections.rb:66:in `constantize'
/Users/jhorsch/.rvm/gems/ruby-2.0.0-p247/gems/sidekiq-3.3.2/lib/sidekiq/processor.rb:46:in `process'
/Users/jhorsch/.rvm/gems/ruby-2.0.0-p247/gems/celluloid-0.16.0/lib/celluloid/calls.rb:26:in `public_send'
/Users/jhorsch/.rvm/gems/ruby-2.0.0-p247/gems/celluloid-0.16.0/lib/celluloid/calls.rb:26:in `dispatch'
/Users/jhorsch/.rvm/gems/ruby-2.0.0-p247/gems/celluloid-0.16.0/lib/celluloid/calls.rb:122:in `dispatch'
/Users/jhorsch/.rvm/gems/ruby-2.0.0-p247/gems/celluloid-0.16.0/lib/celluloid/cell.rb:60:in `block in invoke'
/Users/jhorsch/.rvm/gems/ruby-2.0.0-p247/gems/celluloid-0.16.0/lib/celluloid/cell.rb:71:in `block in task'
/Users/jhorsch/.rvm/gems/ruby-2.0.0-p247/gems/celluloid-0.16.0/lib/celluloid/actor.rb:357:in `block in task'
/Users/jhorsch/.rvm/gems/ruby-2.0.0-p247/gems/celluloid-0.16.0/lib/celluloid/tasks.rb:57:in `block in initialize'
/Users/jhorsch/.rvm/gems/ruby-2.0.0-p247/gems/celluloid-0.16.0/lib/celluloid/tasks/task_fiber.rb:15:in `block in create'
1

1 Answers

2
votes

Your pass nil as photo_id argument in worker because Photo is not saved yet:

"args"=>[nil]

I think will be better to use carrierwave_backgrounder in your case for process images in background.