delayed_job挂钩没有在Heroku上执行

时间:2012-04-14 00:35:04

标签: ruby heroku delayed-job

我正在使用延迟作业在Heroku上发送电子邮件,并且需要能够执行各种钩子后处理。下面的代码在开发环境中运行良好,但在Heroku上运行时无法执行。

class Notification < ActiveRecord::Base

  # Handler for Delayed Notifications Hooks
  #- takes in a Delayed::Job object and an optional exception
  def self.processed!(job,exception=nil)
     pay = job.payload_object.args
     # ... do something with the payload object here
  end

  class << self
    def deliver(method,to,ref_obj)
      to.each do |email|
        n = Notification.new(:method => method,:to => email,:delivery=>'email')
        n.obj = ref_obj
        n.save
        # This is where we send the actual email via ActionMailer
        Email.send(method, n).deliver
      end
    end
    handle_asynchronously :deliver

    # Failure handler for Delayed::Job.  
    # Marks our Notification Object as failed
    def error(job,exception)
      Notification.processed!(job,exception)
    end 
    # Success handler for Delayed::Job.  
    # Marks our Notification Object as sent
    def success(job)
      Notification.processed!(job)
    end
  end
end

这就是打电话的方式:

user = User.find()   # Fetch a user object
Notification.deliver('joined','someone@email.com',user)

通过Email.joined正确发送电子邮件,已成功从数据库中删除延迟作业记录,但永远不会调用延迟作业挂钩success

同样,这在开发中完美运行,但在部署到Heroku时无法工作。

0 个答案:

没有答案