class User < ApplicationRecord
def update_avatar
#some avatar image processing
end
handle_asynchronously :update_avatar, queue: :image_processing
end
我使用gemdelayed_job_active_record
,默认配置失败的作业为delete_failed_jobs: true
。我想不删除队列image_processing
上的作业,我该如何实现这种情况?
如本文所述,要为销毁覆盖Delayed::Worker.destroy_failed_jobs
的失败作业设置每个作业的默认值,可以定义destroy_failed_jobs?方法
NewsletterJob = Struct.new(:text, :emails) do
def perform
emails.each { |e| NewsletterMailer.deliver_text_to_email(text, e) }
end
def destroy_failed_jobs?
false
end
end
在你的例子中类似于这样:
class YourJob
...
def destroy_failed_jobs?
queue_name != 'image_processing'
end
end