【发布时间】:2015-09-02 22:53:59
【问题描述】:
我正在开发一个 Rails 4.1 引擎来处理用户上传的照片和视频。我使用 Mongoid-Paperclip 来处理上传和 Paperclip-av-transcoder 将视频编码成多种格式。所有文件都存储在 S3 中。所有这些工作正常,但正如您所料,对视频进行编码可能需要相当长的时间,因此下一步是在后台进行。我做了一些谷歌搜索,发现Delayed_Paperclip 似乎可以满足我的需要。在那之后,Sidekiq 似乎是处理后台处理的最佳选择。
现在的问题是,我无法将所有这些一起工作。运行我的单元测试,我得到了NoMethodError: undefined method 'process_in_background',所以看起来问题出在 Delayed_Paperclip 上,尽管没有对其进行特殊设置。
这是引发问题的模型
module MyEngine
class Video
include Mongoid::Document
include Mongoid::Paperclip
has_mongoid_attached_file :file,
:path => ':hash.:extension',
:hash_secret => "the-secret",
:storage => :s3,
:url => ':s3_domain_url',
:s3_credentials => File.join(Rails.root, 'config', 's3.yml'),
:bucket => "my-bucket-#{Rails.env}",
:styles => {
:mp4 => { :format => 'mp4', :convert_options => { :output => { :vcodec => 'libx264', :acodec => 'copy' } } },
:ogg => { :format => 'ogg', :auto_rotate => true },
:webm => { :format => 'webm', :auto_rotate => true },
:thumb => { :geometry => "250x187#", :format => 'jpg', :time => 10, :auto_rotate => true }
},
:processors => [:transcoder]
validates_attachment :file, :content_type => { :content_type => ["video/x-flv", "video/mp4", "video/ogg", "video/webm", "video/x-ms-wmv", "video/x-msvideo", "video/quicktime", "video/3gpp"] }
process_in_background :file
end
end
我尝试将require "delayed_paperclip" 添加到lib/myengine/myengine.rb 文件中,但这没有帮助。
关于 Sidekiq,我在test_helper.rb 中添加了以下内容:
require 'sidekiq/testing'
Sidekiq::Testing.inline!
请注意,我没有忘记运行 bundle install 并且 Redis 已启动并运行。我正在使用 Mongoid,而不是活动记录。
我做错了什么?有没有人成功使用过这个设置?我应该尝试另一种宝石组合吗?
附加信息:
- Delayed_paperclip 2.9.1
- Mongoid 4.0.2
- Mongoid-Paperclip 0.0.9
- 回形针 4.2.1
- Paperclip-av-transcoder 0.6.4
- Rails 4.1.9
- Sidekiq 3.5.0
【问题讨论】:
标签: ruby-on-rails-4 mongoid paperclip sidekiq delayed-paperclip