2
我基本上是在Railscast 383中編寫項目 - 第二部分,當照片直接上傳到AWS S3時,然後由Sidekiq在後臺處理照片以創建縮略圖版本的照片。我在Rails 4上。Sidekiq一遍又一遍地重複同一個作業
我的問題是,Sidekiq作業成功完成後,一再重複,而不是停止。
我哪裏錯了?我看不到我的Railscast的代碼和任何區別,除了我在軌道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
ImageWorker:
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