gpt4 book ai didi

ruby-on-rails - 开发环境中的 Rails delayed_job

转载 作者:行者123 更新时间:2023-12-02 15:32:43 25 4
gpt4 key购买 nike

假设您在 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

订单.rb:

      if self.shop.email_preference.on_order?
ReportMailer.delay.order_received(self) unless self.source == "pos"
end

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

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

最佳答案

delayed job worker需要运行,

对于开发模式运行:

RAILS_ENV=development bundle exec bin/delayed_job start

你可能会遇到这样的错误:

bash: bin/delayed_job: No such file or directory

因此您必须生成运行该命令的 bin/delayed_job 文件:

bundle exec rails generate delayed_job                                                                                                                               

在生产环境中你应该运行:

RAILS_ENV=production bin/delayed_job start

以上命令适用于 Rails 4。对于 Rails 3,您应该:

script/delayed_job 而不是 bin/delayed_job

查看 delayed_jobs 页面了解更多 details

关于ruby-on-rails - 开发环境中的 Rails delayed_job,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22806979/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com