使用carrierwave版本时堆栈级别太深

我正在尝试使用sidekiq worker ,它或多或少地将图像文件保存到数据库(使用carrierwave)。 保存的文件很少,这是从video文件中提取的关键帧。 这就是那个工人的意思。

我的图片上传器定义了几个版本,如下所示:

class KeyframeUploader < CarrierWave::Uploader::Base # ... # Keyframe thumbnail sizes version :small do process resize_to_fill: [180, 180], if: :square? process resize_to_fill: [320, 180], if: :not_square? end version :medium do process resize_to_fill: [460, 460], if: :square? process resize_to_fill: [640, 460], if: :not_square? end version :large do process resize_to_fill: [720, 720], if: :square? process resize_to_fill: [1280, 720], if: :not_square? end private # Checks if image is a square def square? file img = Magick::Image.read(file.path) img[0].columns == img[0].rows end # Oposite to #square? def not_square? file !square? file end end 

问题是,当我试图运行我的Sidekiq Worker时,它会抛出Celluloid::FiberStackError: stack level too deep ,修复它的唯一方法是删除我的版本定义。 仅当没有为上传者分配任何版本时,它才有效。

我已经尝试将保存过程移动到另一个工作人员或使用Carrierwave :: Backgrounder,但我总是得到相同的结果。

你知道我该怎么办吗?


编辑:我的stracktrace是:

SystemStackError:堆栈级别与/usr/local/rvm/rubies/ruby-2.1.1/lib/ruby/2.1.0/irb/workspace.rb:86相比太深

事实certificate,这是载波的错(实际上,osx错误)。 带解释的主题: https : //github.com/carrierwaveuploader/carrierwave/issues/1330

解:

 gem 'rmagick', :require => 'RMagick' 

我会针对你的工人的for循环。

 for i in 1..(frames_to_extract) 

你没有增加我,但你似乎在做一个索引循环。 我会将其切换为使用enumeach_with_index

Rubyist倾向于避免for循环,因为它是一个讨厌的混乱。

  1. 检查你的模型,看看你是否有一个after_save钩子,例如,如果你更新该钩子中的记录,它将回归到一个无限循环中 – 你可能有一个after_save创建作业来制作缩略图,然后存储这些缩略图发起另一份工作
  2. 检查线程安全问题,这是您在此处列出的任何gem
  3. 检查堆栈跟踪,你能看到哪些行重复吗?
  4. 当你不使用sidekiq来处理文件时,是否存在错误?
  5. 问题总是发生或只是在负载下?
  6. Ruby 2.1的RMagick错误 – https://github.com/rmagick/rmagick/issues/100