concurrent-ruby icon indicating copy to clipboard operation
concurrent-ruby copied to clipboard

shutdown and execute a timertask results in double runs

Open herwinw opened this issue 8 years ago • 1 comments

Script as PoC:

puts "Start: #{Time.now}"
task = Concurrent::TimerTask.execute(execution_interval: 3) { puts "In task: #{Time.now}" }
sleep 4
task.shutdown
puts "Restart: #{Time.now}"
task.execute
sleep 6
task.shutdown
puts "End: #{Time.now}"

Example output:

Start: 2017-09-06 12:24:54 +0200
In task: 2017-09-06 12:24:57 +0200
Restart: 2017-09-06 12:24:58 +0200
In task: 2017-09-06 12:25:00 +0200
In task: 2017-09-06 12:25:01 +0200
In task: 2017-09-06 12:25:03 +0200
End: 2017-09-06 12:25:04 +0200

The tekst "In task: 2017-09-06 12:25:00 +0200" is not what I would expect here, this belongs to the first execution. The combination of shutdown and execute results in 1 extra execution of the first timer. if you create a new TimerTask instead, the pending task is not executed.


  • Operating system: linux
  • concurrent-ruby version: 1.0.5
  • concurrent-ruby-ext installed: yes
  • concurrent-ruby-edge used: no

herwinw avatar Sep 06 '17 10:09 herwinw

To make it a bit more clear what I'm trying to do here: create a task that runs at a specific interval, but with an option to trigger a "run now", which would reset the countdown interval as well (so if a task is scheduled every 10 seconds starting at t, and at t+2 a "run now" is triggered, the next scheduled run would be at t+12, not t+10). That does require using run_now: true in the above example, but I prefered the minimal PoC. So maybe there's a simpler solution to this than what I'm trying to achieve.

herwinw avatar Sep 06 '17 10:09 herwinw