Delayed_job,从延迟方法中发送邮件

时间:2012-05-11 10:00:06

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

我有一个延迟的方法 async_checkout_assist 按预期运行,被添加到表中并执行没有任何问题,并在执行后从表中删除,但在该延迟方法中我想发送一个邮件如果condition_is_true但是当我添加邮件行时它不发送邮件:\


class ApplicationController < ActionController::Base

  async = ApplicationController.new #create new instance
  async.async_checkout_assist #call method

  def async_checkout_assist
    Mailer.delay.mailer_checkout_assist(@contact_name, @contact_email, @contact_tel)
  end

  end
  handle_asynchronously :async_checkout_assist, :run_at => Proc.new { 10.seconds.from_now }

end

更新

延迟方法(async_checkout_assist)由工作人员添加并运行

SQL (14.1ms)  INSERT INTO `delayed_jobs` (`attempts`, `created_at`, `failed_at`, `handler`, `last_error`, `locked_at`, `locked_by`, `priority`, `queue`, `run_at`, `updated_at`) VALUES (0, '2012-05-11 10:14:27', NULL, '--- !ruby/object:Delayed::PerformableMethod\nobject: !ruby/object:ApplicationController\n _routes: !!null \n _action_has_layout: true\n _headers:\n Content-Type: text/html\n _status: 200\n _request: !!null \n _response: !!null \nmethod_name: :async_checkout_assist_without_delay\nargs: []\n', NULL, NULL, NULL, 0, NULL, '2012-05-11 10:14:37', '2012-05-11 10:14:27')
   (17.2ms)  COMMIT


Marais-Mac-mini:cybercellar.com_heroku davidmuller$ rake jobs:work
[Worker(host:Marais-Mac-mini.local pid:886)] Starting job worker
[Worker(host:Marais-Mac-mini.local pid:886)] ApplicationController#async_checkout_assist_without_delay completed after 9.5160
[Worker(host:Marais-Mac-mini.local pid:886)] Class#mailer_checkout_assist completed after 7.3627
[Worker(host:Marais-Mac-mini.local pid:886)] 2 jobs processed at 0.0923 j/s, 0 failed ...

现在可以同时使用

Mailer.delay.mailer_checkout_assist(@contact_name, @contact_email, @contact_tel)
Mailer.mailer_checkout_assist(@contact_name, @contact_email, @contact_tel).deliver

0 个答案:

没有答案