开发环境中的Rails delay_job

Mar*_*ins 2 email ruby-on-rails actionmailer

假设您有一个在 Rails 中执行操作的邮件程序,它是从某个模型使用 调用的delay,例如:

class ReportMailer < ActionMailer::Base

  default from: "hello@shopstar.co.za"

  def order_received(order)
    @order = order
    mail(:to => @order.shop.email, :subject  => "You have a new order on Shopstar")
  end
end
Run Code Online (Sandbox Code Playgroud)

订单.rb:

      if self.shop.email_preference.on_order?
       ReportMailer.delay.order_received(self) unless self.source == "pos"
      end
Run Code Online (Sandbox Code Playgroud)

这会从开发环境发送邮件吗?

这会在生产版本中发送邮件吗?

Nim*_*mir 6

延迟工作的工作人员需要运行,

对于开发模式运行:

RAILS_ENV=development bin/delayed_job start
Run Code Online (Sandbox Code Playgroud)

在生产中,您应该运行:

RAILS_ENV=production bin/delayed_job start
Run Code Online (Sandbox Code Playgroud)

以上命令适用于Rails 4。对于Rails 3,你应该这样做:

script/delayed_job 代替 bin/delayed_job

查看delayed_jobs 页面了解更多详情