我在使用Sidekiq和Sidetiq发送重复邮件时遇到问题。我几乎尝试了一切,但我找不到解决方案。 我有Sidekiq工人,看起来像这样:
class InvoiceEmailSender
include Sidekiq::Worker
include Sidetiq::Schedulable
recurrence {minutely(2)}
def perform(invoice_id, action)
@invoice = Invoice.find(invoice_id.to_i)
if action == "invoice"
send_invoice
else
send_reminder
end
end
private
def send_invoice
if @invoice.delivery_date == Date.today
InvoiceMailer.delay.send_invoice(@invoice)
else
InvoiceMailer.delay_for(@invoice.delivery_date.to_time).send_invoice(@invoice)
end
end
def send_reminder
InvoiceMailer.delay.send_invoice_reminder(@invoice) unless @invoice.paid?
end
end
在控制器中结束我以这种方式使用它:
InvoiceEmailSender.perform_async(@invoice.id, "invoice")
当我尝试发送此电子邮件时,我在sidekiq控制台中出现以下错误:
2014-08-26T05:36:01.107Z 4664 TID-otcc5idts WARN: {"retry"=>true, "queue"=>"default", "class"=>"InvoiceEmailSender", "args"=>[1409031120.0, 1409031240.0], "jid"=>"06dc732831c24e1a6f78d929", "enqueued_at"=>1409031120.7438812, "error_message"=>"Couldn't find Invoice with 'id'=1409031120", "error_class"=>"ActiveRecord::RecordNotFound", "failed_at"=>1409031249.1003482, "retry_count"=>2, "retried_at"=>1409031361.1066737}
2014-08-26T05:36:01.107Z 4664 TID-otcc5idts WARN: Couldn't find Invoice with 'id'=1409031120
2014-08-26T05:36:01.107Z 4664 TID-otcc5idts WARN: /home/mateusz/.rvm/gems/ruby-2.0.0-p0@rails4/gems/activerecord-4.1.2/lib/active_record/relation/finder_methods.rb:320:in `raise_record_not_found_exception!'
在计划选项卡中的sideiq网络监视器中,它看起来像这样:
请帮助,因为我不知道发生了什么......
答案 0 :(得分:2)
传入的数据看起来像纪元时间戳,结果是Sidetiq将最后和当前时间作为2个参数传递给您的工作人员according to the documentation。
我不确定你如何与预定的工作人员一起使用自定义参数,你可能需要一个不同的策略,而不是尝试创建更多的预定工作人员,只需要1(或两个,因为看起来你让这个班做2个工作)计划工人处理工作清单,每隔一段时间做一次。