调用延迟作业定义的正确方法

时间:2012-09-01 15:31:29

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

我在我的应用程序中使用delayed_job进行某些进程。它没有任何效果并且可以动态运行代码。以下是代码。

Module1::some_definition(param).delay(priority=>3, :run_at=>2.minutes.from_now)

我做错了吗?

更新 这就是我所做的dimitko建议。但我仍然得到错误。

class User < ActiveRecord::Base
  def do_something
      #Google is my module and the do_some_process is definition.
      Google.delay.do_some_process
  end
end

2 个答案:

答案 0 :(得分:0)

.delay的想法是将其与您想要调用的实际工作方法联系起来。

class User < ActiveRecord::Base
  def do_something
  # ... do something long which you want to be in the background...
  end
end

使用delayed_job延迟此代码的“正确”方法是:

User.current.delay(priority=>3, :run_at=>2.minutes.from_now).do_something

我认为delayed_job不打算在模块中注入.delay方法,如示例代码所示。

答案 1 :(得分:-1)

您也可以尝试设置Cron作业。我通常创建一个rake任务,然后使用Cron作业运行它。

由于