Ruby on rails 延迟作业:使用可变执行时间异步处理_
我想在X秒后运行一个延迟函数。 X由物体的场决定 我试过这个:Ruby on rails 延迟作业:使用可变执行时间异步处理_,ruby-on-rails,ruby,asynchronous,delayed-job,Ruby On Rails,Ruby,Asynchronous,Delayed Job,我想在X秒后运行一个延迟函数。 X由物体的场决定 我试过这个: # after_create this function is triggered def save_distance update_attribute :distance, 5 end # function gets delayed by X seconds (X = field named "timespan" of my object) handle_asynchronously :save_distance, :r
# after_create this function is triggered
def save_distance
update_attribute :distance, 5
end
# function gets delayed by X seconds (X = field named "timespan" of my object)
handle_asynchronously :save_distance, :run_at => Proc.new { timespan.seconds.from_now }
但它不起作用,返回:
undefined local variable or method `timespan' for #<Class:0x007f9b9d4f4c88>
未定义的局部变量或方法“timespan”#
如何实现这一点?您需要将一个参数传递给proc
handle_asynchronously :save_distance, :run_at => Proc.new {|object| object.timespan.seconds.from_now }