正在从数据库中删除作业而不进行处理

时间:2013-08-06 04:47:09

标签: ruby-on-rails-3 delayed-job

如果没有delayed_job gem和相关代码更改,电子邮件将通过我的应用程序正确处理。

在github wiki上找到common problems指南,在“工作被静默地从数据库中删除”标题下的gem,我做了以下内容:

/config/initializers/delayed_job.rb

Delayed::Worker.destroy_failed_jobs = false

重新启动工作人员和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

关于如何进一步解决此问题的任何想法?

1 个答案:

答案 0 :(得分:0)

尝试这样做:

创建初始化程序并添加行

require 'ri_cal'

现在试着让我知道它是怎么回事。