2013-09-24 69 views
-1

我想每五分鐘調用一次特定的函數。如何以固定的時間間隔調用函數?

我在一個字符串變量中累積數據,然後我想要一個函數來處理它。

如何在Ruby中執行此操作?

+0

可能重複: //stackoverflow.com/questions/5369459/ruby-task-scheduler) – screenmutt

+0

Anushka!請閱讀[如何問一個好的問題手冊](http://stackoverflow.com/questions/how-to-ask)。或者我編譯的[Newbie Manual](http://grahn.us/projects/stack-overflow.php) – screenmutt

+0

你也可以試試gem [when](https://github.com/javan/whenever) –

回答

1

檢查rufus-scheduler

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 
+0

我是不知道這個*寶石* ..謝謝你讓我知道.. * + 1 * ... –

2

這裏提供了一個毒啓用/禁用在另一個線程你的函數調用一個例子:

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 
[紅寶石任務調度程序(HTTP的
相關問題