Sidekiq工人类不使用CarrierWave上传

时间:2015-03-15 02:30:12

标签: ruby-on-rails ruby-on-rails-4 carrierwave sidekiq

我正在尝试在某些图像处理上运行延迟作业并遇到一些问题。

在创建操作中,我首先创建了一个没有图像属性的新实例,因此上传者可以使用模型值。然后调用后台作业来执行图像上载/处理。

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

通过将图像调用移动到Worker类,我不认为params哈希现在可用。该页面只加载了上传器中的默认图像集,但是从未出现过新的缩略图,看到处理和版本控制从未发生过。

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

---如果我注释了perform方法中的所有代码仍然会出错。

以下是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 个答案:

答案 0 :(得分:2)

您在传递nil作为photo_id参数,因为Photo尚未保存:

"args"=>[nil]

我认为最好在你的情况下使用carrierwave_backgrounder来处理背景中的过程图像。