ruby-on-rails - 带有sidekiq的delayed_paperclip返回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
解决方案
推荐阅读
- python - 如何计算Python中每行(id)的旧时间戳数
- security - 对于使用 Google 或 Facebook 帐户注册的用户,在我的应用程序中删除帐户的安全方法是什么?
- spring-boot - Spring @Retryable 可根据客户端配置延迟
- git - 推入 Gitkraken,它是否使用强制租赁?
- c# - 如何读取列表框中的 SelectedItems 的名称并将它们输出到文本框?
- react-native - 使用 generator-rn-toolbox 应用图标和闪屏时出现问题
- angular - `ERROR 错误:无法匹配任何路由。` - 角度路由器
- c# - 我的 `Enumerable.Range(,)` 发生了什么?
- c++ - 一种在 C++ 中将类数据存储到文件的有效方法
- registry - 触发 RunOnce 或排除故障