我在使用 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 网络监视器中,它看起来像这样:
请帮忙,因为我不知道发生了什么......