2012-09-01 26 views
0

我在我的應用程序中爲某些進程使用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 

回答

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方法爲您的示例代碼提示。

+0

所以,你的意思是dat模塊不能與delayed_job一起使用。 –

+0

我相信如此。您可以通過以下方式自由查看代碼:https://github.com/collectiveidea/delayed_job – dimitarvp

+0

當您嘗試使用您的代碼建議進行測試時,我收到以下錯誤...用戶#do_something與NoMethodError失敗:未定義方法'do_something'對於#

-1

您也可以嘗試設置Cron作業。我通常創建一個rake任務,然後使用Cron作業運行該任務。

謝謝