我试图拖延以一天一列(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