【问题标题】:Sidekiq worker class not working with CarrierWave UploadSidekiq 工人阶级不使用 CarrierWave Upload
【发布时间】:2015-05-17 08:58:29
【问题描述】:

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

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

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'

【问题讨论】:

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


    【解决方案1】:

    您将 nil 传递为 worker 中的 photo_id 参数,因为 Photo 尚未保存:

    "args"=>[nil]
    

    我认为在您的情况下使用carrierwave_backgrounder 处理后台图像会更好。

    【讨论】:

    • 谢谢。我碰巧遇到了同样的错误,现在尝试使用carrierwave background gem。正如我的新堆栈溢出帖子中提到的那样,仍然存在一些问题。 stackoverflow.com/questions/29134806/…
    猜你喜欢
    • 1970-01-01
    • 2018-01-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-01-03
    • 2012-07-12
    • 2017-02-23
    • 1970-01-01
    相关资源
    最近更新 更多