1

当有人填写表格时,我正在尝试使用 Heroku 上的 Rails 3.2 应用程序中的延迟作业发送电子邮件。我已经能够通过本地开发机器上的延迟作业成功发送电子邮件。如果我通过 Heroku 上的控制台手动运行它们,我还可以使用延迟作业发送电子邮件。但是,当有人提交触发电子邮件的表单时,它不会发送。

这是我的邮件:

class ClaimMailer < ActionMailer::Base
  default from: "noreply@coatchex.com"

  def patron(claim)
    mail(:to => claim.email, :subject => I18n.t('mailers.claims.patron.subject'))
  end

  def coatchex(claim)
    @claim = claim
    mail(:to => 'claims@coatchex.com', :subject => I18n.t('mailers.claims.coatchex.subject'))
  end
end

这是我的控制器:

class ClaimsController < ApplicationController
  layout 'basic'

  def new
    @claim = CoatChex::Forms::Claim.new
  end

  def create
    @claim = CoatChex::Forms::Claim.new(params[:claim])
    if @claim.valid?
      ClaimMailer.delay.coatchex(@claim)
      render :thank_you
    else
      render :new
    end
  end
end

就像我提到的,如果我通过 Heroku 控制台运行以下命令,它会将电子邮件排入延迟作业并发送它就好了:

@claim = ...
ClaimMailer.delay.coatchex(@claim)

但是,每当我通过表单发送它时,它都不会触发。

如果我足够快,我可以在 Heroku 控制台中运行 Delayed::Job.count 并在通过表单提交时在作业执行之前看到值 1。所以我知道延迟的工作正在得到它。如果我使用

heroku logs -p worker -t

我可以看到在手动执行时记录作业过程,但在通过表单时看不到。

数据库中没有失败的作业。

以前有人遇到过这样的事情吗?

4

2 回答 2

0

我有一个类似的问题。一个很好的起点是https://devcenter.heroku.com/articles/delayed-job#debugging上的信息- 特别Delayed::Job.last.last_error是在 Heroku 控制台上运行的信息。

在我的情况下,我得到的错误是Job failed to load: uninitialized constant Syck::Syck,通过添加psych到我的 gemfile 来修复它。请参阅Delayed_job: Job failed to load: uninitialized constant Syck::Syckhttp://effectif.com/ruby-on-rails/syck-and-psych-yaml-parsers-on-heroku

于 2013-02-17T13:48:02.177 回答
0

您需要使用命令启动worker

rake jobs:work

在你的 heroku rails 控制台上。

于 2015-09-01T12:28:07.967 回答