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

mba*_*jur 11 ruby ruby-on-rails carrierwave sidekiq

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

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

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
Run Code Online (Sandbox Code Playgroud)

问题是,当我试图运行我的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相比太深

mba*_*jur 40

事实证明,这是载波的错(实际上,osx错误).线程说明:https://github.com/carrierwaveuploader/carrierwave/issues/1330

解:

gem 'rmagick', :require => 'RMagick'
Run Code Online (Sandbox Code Playgroud)