Skip to content

shutdown and execute a timertask results in double runs #672

Open
@herwinw

Description

@herwinw

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

Activity

herwinw

herwinw commented on Sep 6, 2017

@herwinw
Author

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.

added
enhancementAdding features, adding tests, improving documentation.
on Feb 25, 2018
added this to the 1.1.0 milestone on Feb 25, 2018
added
looking-for-contributorWe are looking for a contributor to help with this issue.
and removed on Jun 29, 2018
removed this from the 1.1.0 milestone on Jul 6, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementAdding features, adding tests, improving documentation.looking-for-contributorWe are looking for a contributor to help with this issue.medium-priorityShould be done soon.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Participants

      @pitr-ch@herwinw

      Issue actions

        shutdown and execute a timertask results in double runs · Issue #672 · ruby-concurrency/concurrent-ruby