首页 > 解决方案 > 带有sidekiq的delayed_pa​​perclip返回NoMethodError:nil的未定义方法`fetch':NilClass

问题描述

我正在使用delayed_paperclip并且我已经尝试使用默认的 ActiveJob 并且效果很好。但是,它是同步运行的,所以它会在响应之前等待作业完成,所以我想将队列移动到 sidekiq。

但是现在我已经将队列移动到 sidekiq,它给了我一个错误:

NoMethodError: undefined method `fetch' for nil:NilClass

我试图寻找答案,但我没有找到运气。

我将此添加到我的application.rb

config.active_job.queue_adapter = :sidekiq

我的图像模型

    has_attached_file :attachment,
                  styles: {
                      mini: '48x48#',
                      thumb: '75x95#',
                      tile: '212x212#',
                      tile_portrait: '230x327#',
                      large_tile: '300x300#',
                      small: '100x100#',
                      product: '240x240',
                      large: '360x460#',
                      large_portrait: '460x654#',
                      zoom_portrait: '690x981#'
                  },

    process_in_background :attachment, processing_image_url: :processing_image_fallback

    def processing_image_fallback
      options = attachment.options
      options[:interpolator].interpolate(options[:url], attachment, :original)
    end

有谁知道问题是什么?或者有没有一种方法可以让我只使用 ActiveJob 但我怎样才能让它在后台处理回形针?

这是我的图片上传代码

def create_images
  return if context.image == {}
  context.images.each do |key, image|
    new_image_record = Image.create(
    kind: context.type
  ) #what I want to achieve: move on to next after creation 
  new_image_record.attachment = image
  new_image_record.save #job runs here. hoping this will run in the background or be moved to sidekiq
end

标签: ruby-on-railsrubypaperclipsidekiqdelayed-paperclip

解决方案


推荐阅读