我試圖拖延以一天一列(yest_shareholder_count
)增量每當爲了創建一個investment
記住這有一個venture
一天前的investment
用戶數量的記錄(遞增因此我可以使用這些數據生成追蹤投資者數量的圖表)。使用delayed_job的
我覺得最簡單的方法是使用delayed_job
,但這是行不通的。 delayed_job是在單獨的表中創建的,根據SQLite數據庫瀏覽器,它在一天後運行。 但yest_shareholder_count列未被增加。
Venture
型號:
def yest_increment
self.increment!(:yest_shareholder_count)
end
handle_asynchronously :yest_increment, :run_at => Proc.new {1.minute.from_now}
Investments
控制器:
def create
@venture = Venture.find(params[:share_id])
@venture_increment= @venture.increment(:shareholder_count)
@venture_yest_increment= @venture.yest_increment
@investment = current_user.invest!(@venture)
if @venture_increment.save and @venture_yest_increment.save
respond_to do |format|
format.html {redirect_to @venture}
end
end
end
直截了當的增量情況發生,因爲它應該,但延遲增量從來不會。
這些都是在delayed_jobs表中的「處理程序」欄中的內容,以防萬一他們是有用的:
--- !ruby/struct:Delayed::PerformableMethod
object: !ruby/ActiveRecord:Venture
attributes:
created_at: 2011-06-21 07:00:12.252808
onemth_shareholder_count: 0
updated_at: 2011-08-09 16:50:36.864354
onewk_shareholder_count: 0
shareholder_count: 4
id: 49
user_id: 40
yest_shareholder_count: 0
method_name: :yest_increment_without_delay
args: []
我不知道這裏的「yest_increment_without_delay」是從哪裏來的,爲什麼「 args「是空白的...
任何幫助非常感謝。
編輯:我有「1.minute.from_now」而不是「1.day.from_now」只是爲了測試代碼。
感謝您的回答。問題是該值不會遞增。 – jonic
對不起 - 這不清楚。剛剛編輯了這個問題。 – jonic
'yest_increment'應該返回什麼?它不會返回,因爲延遲的工作會攔截呼叫而不會調用該方法。從控制檯調用'yest_increment_without_delay'是否正確增加? – rubish