无法在数据库中找到延迟作业记录

时间:2016-04-26 16:20:34

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

我是Delayed Jobs的新手,我不确定我是否正确这样做。

工人

class BillingFailedEmailWorker < BaseWorker

  attr_accessor :car

  def initialize(car)
     @car = car 
  end

  def billing_failed_for_subscriptions
    StripeMailer::billing_failed_for_subscriptions(car.owner.email).deliver
  end

  def perform
    self.class.new(car).delay(
      run_at: DateTime.now + 1.week,
      queue: "Failed Subscription"
    ).billing_failed_for_subscriptions
  end  
end

邮件程序

class StripeMailer < ActionMailer::Base

  default from: Settings.default_from_email

  def billing_failed_for_subscriptions(email)
    mail to: email, subject: 'Autobrain Subscription Renewal Failed'
  end
end

billing_failed_for_subscriptions显然也对应于正确的邮件程序视图。

我的问题是当我运行BillingFailedEmailWorker.new(Car.last).perform时,我看到命令在Delayed::Backend::ActiveRecord::Job中正确执行,但是当我运行Delayed::Backend::ActiveRecord::Job.lastDelayed::Job.last时,我看不到我刚才的工作创建。

这可能是我的Rails环境正在开发中还是我缺少的东西?

1 个答案:

答案 0 :(得分:0)

而不是使用

  • StripeMailer :: billing_failed_for_subscriptions(car.owner.email).deliver

使用

  • StripeMailer :: billing_failed_for_subscriptions(car.owner.email).deliver_later 然后在控制台中,您可以将其检查为Delayed :: Job.last