所以我有一些电子邮件没有出去,因为没有实例化邮件服务API密钥。但是,详细信息模型对象被保存在数据库中。我不想在数据库中重新创建它们。我可以发送delayed_job一个内存中唯一的ActiveRecord对象吗?
我编写了一个rake任务来发送电子邮件,并且它更容易尝试创建一些临时内存中对象,而不是尝试根据detail_params中的内容找到正确的ActiveRecord对象。然后,我用DetailMailerJob发送的电子邮件,并通过在实例化详细对象。
temp_obj = Detail.new(detail_params)
DetailMailerJob.new.delay.notify_job(temp_obj)
但我运行rake任务后,注意到在延迟:: Job.all队列以下错误:
last_error: "ActiveRecord::RecordNotFound
这是否意味着只办法,我在通详细对象为DetailMailerJob是先找到数据库实例化的记录? (即,没有在内存中的对象)
编辑:这里是DetailMailer & DetailMailerJob类。
class DetailMailerJob
def notify_job(detail)
DetailMailer.notify_job(detail).deliver
end
end
class DetailMailer < ActionMailer::Base
def notify_job(detail)
@detail = detail
@emailed_to = detail.emailed_to.join(", ")
mail(to: detail.emailed_to, subject: "#{detail.full_name} - New Message")
end
end
如果不知道“DetailMailerJob”中有什么,就不可能回答这个问题。这就是产生错误的原因! – Gene
感谢您的建议基因。更新。 – Nona