@iteration = 0
Repeat::Every 5.seconds, :strict => false do
@iteration += 1
iteration = @iteration.to_i # threadsafety for the test
15.times do |i|
# Simulate a broken process, taking three times as long as the duration wants to allow
puts iteration.to_s + ('*' * i)
sleep 1
end
end
output with :strict => false # default
# It's supposed to repeat every 5 seconds, but the process takes ten seconds each time - pretending these are extra-long iterations, non-strict tracing will wait for them to finish before starting the next one.
1
1*
1**
1***
1****
1*****
1******
1*******
1********
1*********
1**********
1***********
1************
1*************
1**************
2
2*
2**
2***
2****
2*****
2******
2*******
2********
2*********
2**********
2***********
2************
2*************
2**************
3
3*
3**
3***
3****
3*****
3******
3*******
3********
3*********
3**********
3***********
3************
3*************
3**************
output with :strict => true
# With strict time tracking, it won't wait for longer-running iterations to complete; it will always start at exactly the right time (as much as possible) without worrying about how many iteration's threads are still running. Be careful with this, it detaches processes and then garbage collects the references to the threads in Ruby, so there's no way to stop them programmatically - you'll have to manually kill them if something's gone wrong.
1
1*
1**
1***
1****
2
1*****
2*
1******
2**
1*******
2***
1********
2****
1*********
3
2*****
1**********
3*
2******
1***********
3**
2*******
1************
3***
2********
1*************
3****
2*********1**************