1

我想每五分钟调用一次特定的函数。

我在一个字符串变量中累积数据,然后我想要一个函数来处理它。

我如何在 Ruby 中做到这一点?

4

2 回答 2

3

检查rufus 调度程序

require 'rufus-scheduler'

scheduler = Rufus::Scheduler.new

scheduler.in '5m' do
  your_method(args)
end

scheduler.join
  # let the current thread join the scheduler thread
于 2013-09-24T13:23:53.187 回答
3

这是一个通过提供毒药来启用/禁用另一个线程中的函数调用的示例:

poison = false

t = Thread.new do
  loop do
    break if poison
    your_method(args)
    sleep(5.minutes)
    redo
  end
end
# uncomment the next line if this is your main thread
#t.join
于 2013-09-24T14:20:49.133 回答