如果没有延迟作业 gem 和相关的代码更改,电子邮件将通过我的应用程序正确处理。
按照在 github wiki 上找到的 gem 的常见问题指南,标题为“作业已从数据库中静默删除”,我执行了以下操作:
/config/initializers/delayed_job.rb
Delayed::Worker.destroy_failed_jobs = false
重新启动workers和rails服务器后,我再次尝试,但是当我将电子邮件设置为处理时,我仍然可以看到delayed_job行被添加,然后很快被删除。
正在从控制器调用电子邮件,如下所示:
PresentationMailer.delay.presentation_invitation(@presentation)
从 rails 控制台(预计,我还没有成功运行过作业):
1.9.3p194 :001 > Delayed::Job.last
Delayed::Backend::ActiveRecord::Job Load (0.5ms) SELECT `delayed_jobs`.* FROM `delayed_jobs` ORDER BY `delayed_jobs`.`id` DESC LIMIT 1
=> nil
摘自/log/delayed_job.log
2013-08-06T16:30:54+1200: [Worker(delayed_job host:192.168.1.251 pid:26688)] Job Class#presentation_invitation (id=9) RUNNING
2013-08-06T16:30:54+1200: [Worker(delayed_job host:192.168.1.251 pid:26688)] Job Class#presentation_invitation (id=9) COMPLETED after 0.0081
2013-08-06T16:30:54+1200: [Worker(delayed_job host:192.168.1.251 pid:26688)] 1 jobs processed at 9.1940 j/s, 0 failed
这似乎表明没有错误被击中;但是没有发送邮件(通过wireshark确认,没有数据包发送到我的SMTP服务器)
/app/mailers/presentation_mailer.rb
class PresentationMailer < ActionMailer::Base
helper :application
default from: "alias@domain.test"
def presentation_invitation(email)
return false if email.sent
contact = nil
presentation = nil
if email.emailable.class == PresentationAttendee
contact = email.emailable.contact
presentation = email.emailable.presentation
else
return false
end
ics = RiCal.Event do
description "Presentation"
dtstart DateTime.parse(presentation.date_time)
dtend DateTime.parse((presentation.date_time + 30*60).to_s) # (90 minutes length)
location presentation.presentation_location.to_s
add_attendee contact.email_address
alarm do
description "Presentation"
end
end
attachments["calendar-reminder.ics"] = {mime_type: "text/calendar", content: ics.export}
@email = email
@contact = contact
@presentation = presentation
content_type = "multipart/mixed" # Required for background processing of mail to complete with attachment in tact
mail to: "#{contact.first_name} #{contact.last_name} <#{contact.email_address}>", subject: email.email_content.subject if email.email_content
end
end
关于如何进一步解决此问题的任何想法?