Skip to content

Reimplement TimerTask using promises #829

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 6 commits into from

Conversation

adamruzicka
Copy link
Contributor

@adamruzicka adamruzicka commented Oct 6, 2019

TODO:

  • update docs
  • implement soft shutdown
  • handle re-execution

Copy link
Member

@pitr-ch pitr-ch left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for this rewrite, this is much better. Let know if you need any help with the final changes.

@adamruzicka
Copy link
Contributor Author

The final changes are pretty straightforward, I just need to find time to actually implement them, hopefully sometime during this week.

Comment on lines +245 to +249
def shutdown
# TODO: Implement soft shutdown
kill
end
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How exactly should soft shutdown behave?

Copy link
Member

@pitr-ch pitr-ch Nov 26, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hm I think there are actually 3 levels to consider.

  • stop: finish task if running, do not schedule a new tasks
  • shutdown: also cancel running task, do not schedule a new tasks
  • kill: kill running tasks by killing it's thread, do not schedule a new tasks

What did the old implementation support?
For the new one I think all 3 make sense, could you implement them? Please free to experiment with the names or API for this, I am not sure myself what will be the best option.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure if we can do kill in a sensible way, will take a look what we can do

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The kill will always be dangerous. However, has to be there since the other methods can fail :/ It should be only used as a last resort when the previous methods failed to finish. If you run out of time just put raise NotImplemented there, or we could also meet for coffee and figure something together.


@Channel = opts[:channel]

@Stopped = false
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This one is not immutable. It got renamed by mistake.

self.execution_interval = opts[:execution] || opts[:execution_interval] || EXECUTION_INTERVAL
self.timeout_interval = opts[:timeout] || opts[:timeout_interval] || TIMEOUT_INTERVAL

@Channel = opts[:channel]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we discussed some problems which could arise if we allow the channel to be shared between two timer-tasks. Like the arriving messages would not have clear sender. Is that right? It would be better if it would accept arguments for creating the channel, where new channel would be created on dup, or to add dup support on the channel and dup it as well in timer-task's dup.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right, how about we drop the reuse of channel in #dup. This way #duped timers won't have a channel, unless a new channel is provided when #dup is called?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That would work but I think it would more surprising. Assuming that a duped timer-task is most often used in the same place/functional-context as the template than it would be expected the new timer-task to have a channel as the parent has.

Comment on lines +245 to +249
def shutdown
# TODO: Implement soft shutdown
kill
end
Copy link
Member

@pitr-ch pitr-ch Nov 26, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hm I think there are actually 3 levels to consider.

  • stop: finish task if running, do not schedule a new tasks
  • shutdown: also cancel running task, do not schedule a new tasks
  • kill: kill running tasks by killing it's thread, do not schedule a new tasks

What did the old implementation support?
For the new one I think all 3 make sense, could you implement them? Please free to experiment with the names or API for this, I am not sure myself what will be the best option.

@mhenrixon
Copy link

Any news on this? Also, will this PR prevent the problem that TimerTask spins up a limitless number of threads in certain scenarios?

@chrisseaton
Copy link
Member

Are people still interested in this PR? If so we can work on it.

@mhenrixon
Copy link

@chrisseaton well at this point it would really complicate things for me since I now maintain a version of timer task that fixes the thread leak issue: https://github.com/mhenrixon/sidekiq-unique-jobs/blob/main/lib/sidekiq_unique_jobs/timer_task.rb

I still feel like the timer task shouldn't be leaking threads (and therefor memory) so yeah, please fix it! 😂

@chrisseaton
Copy link
Member

Since this is a draft PR, the author isn't looking to work on it any more, the branch has conflicts, and the work is incomplete, I'm closing it.

Thanks anyway for it. If someone does want to merge it, we're open to that.

@chrisseaton chrisseaton closed this Mar 7, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants