【发布时间】:2013-08-06 04:47:08
【问题描述】:
如果没有延迟作业 gem 和相关的代码更改,电子邮件将通过我的应用程序正确处理。
按照在 github wiki 上找到的 common problems 指南,在标题为“作业从数据库中静默删除”下的 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
关于如何进一步解决此问题的任何想法?
【问题讨论】:
-
将delayed_job 日志文件发布到日志文件夹中。检查一下。
-
delayed_job 日志摘录已发布。
-
你有没有延迟的作业初始化器?如果是这样发布它。这很奇怪。还有一个建议是您是否可以创建一个非邮件作业并查看它是否有效。
-
你能把邮件也发一下吗?
-
有一个单行初始化程序,就在我的帖子顶部附近。除了与delayed_job 相关的内容外,没有其他内容。邮寄者已发布。
标签: ruby-on-rails-3 delayed-job