【问题标题】:Delayed Jobs: handle_asynchronously with variable execution time延迟作业:以可变执行时间异步处理
【发布时间】:2017-12-02 03:23:12
【问题描述】:

我想在 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, :run_at => Proc.new { timespan.seconds.from_now }

但它不起作用,返回:

undefined local variable or method `timespan' for #<Class:0x007f9b9d4f4c88>

怎么做?

【问题讨论】:

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


    【解决方案1】:

    你需要给proc传入一个参数

    handle_asynchronously :save_distance, :run_at => Proc.new {|object| object.timespan.seconds.from_now }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-03-29
      • 1970-01-01
      • 1970-01-01
      • 2011-03-12
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多