2012-02-28 52 views
1

我有一個定期運行的Rufus「每項工作」,但有時可能無法執行它的任務。如何重新安排失敗的Rufus每項工作?

失敗時,我想盡快重新安排重試,而不是等到下一個週期。

class PollProducts 

    def initialize() 
    end 

    def call(job) 
    puts "Updating products" 

    begin 
     # Do something that might fail 
     raise if rand(3) == 1 
    rescue Exception => e 
     puts "Request failed - recheduling: #{e}" 
     # job.in("5s") <-- What can I do? 
    end 
    end 
end 

scheduler.every '6h', PollProducts.new, :first_in => '5s', :blocking => true 

這可能嗎?

回答

2

好這個工作對我來說:

job.scheduler.in '5s', self