我基本上是在Railscast 383中编写项目- 第二部分,当照片直接上传到 AWS S3 时,然后由 Sidekiq 在后台处理照片以创建照片的缩略图版本。我在 Rails 4 上。
我的问题是 Sidekiq 工作在成功完成后会不断重复,而不是停止。
我哪里错了?我看不出我的代码和 Railscast 的代码有什么区别,除了我在 Rails 4 上(这么强的参数而不是attr_accessible
)
照片类:
class Photo < ActiveRecord::Base
mount_uploader :image, ImageUploader
default_scope order('updated_at DESC')
after_save :enqueue_image
def image_name
File.basename(image.path || image.filename) if image
end
def enqueue_image
ImageWorker.perform_async(id, key) if key.present?
end
end
图像工作者:
class ImageWorker
include Sidekiq::Worker
sidekiq_options retry: false
# sidekiq_options retry: 3
def perform(id, key)
photo = Photo.find(id)
photo.key = key
photo.remote_image_url = photo.image.direct_fog_url(with_path: true)
photo.save!
photo.update_column(:image_processed, true)
end
end
上传者:
class ImageUploader < CarrierWave::Uploader::Base
include CarrierWaveDirect::Uploader
include CarrierWave::RMagick
# storage :fog
#### storage defaults to fog when CarrierWaveDirect::Uploader is included ####
include CarrierWave::MimeTypes
process :set_content_type
version :thumb do
process :resize_to_limit => [200, 200]
end
version :medium do
process :resize_to_limit => [400, 400]
end
end