Skip to content
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

jobs: prevent parallel execution and plugin specific scheduler #1891

Merged
merged 1 commit into from
Jun 26, 2020

Conversation

Exirel
Copy link
Contributor

@Exirel Exirel commented Jun 16, 2020

Closes #1144

Description

Initially, it was only about preventing parallel execution of jobs, but then I realized I needed way more than that:

  • changed the job object to be registered only once for any set of intervals,
  • changed the job object to have similar meta-data than plugin's rules
  • added a new scheduler, that can be used in a plugin-specific context (similar to the plugin's rules manager)

Also, I realized that the "catch up" mechanism makes no sense: either the job can be run in time, or it can't, but it won't try to run it more than once because it's late. I can see why it was like that before, but there are several problems with how it was implemented:

  • the scheduler is not reliable: it ticks at best every second, at worst every now and then
  • a job isn't aware of the catch up mechanism: is it late? is it on time? it can't know, so it can't adapt itself

In that regard, it's best not to over-engineer the solution, and to just take the most optimistic and safe approach: execute only once at a time, then see if it should execute again or a bit later, given the configured intervals.

And here we are, with a lot of changes for something that seem easy at first. The good news is that it was necessary anyway to work on a better documentation spec for Sopel: in the future, we'll be able to list not only rules and commands, but also jobs! But that will be for a future PR.

Checklist

  • I have read CONTRIBUTING.md
  • I can and do license this contribution under the EFLv2
  • No issues are reported by make qa (runs make quality and make test)
  • I have tested the functionality of the things this change touches

@Exirel Exirel added the Bugfix Generally, PRs that reference (and fix) one or more issue(s) label Jun 16, 2020
@Exirel Exirel added this to the 7.1.0 milestone Jun 16, 2020
@Exirel Exirel requested a review from dgw June 16, 2020 17:09
Copy link
Member

@dgw dgw left a comment

Choose a reason for hiding this comment

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

Not the most comprehensive review, but a start. Couple of actual questions here—for once, I'm not just playing with docstrings. 😛

sopel/bot.py Outdated Show resolved Hide resolved
sopel/bot.py Outdated Show resolved Hide resolved
sopel/plugins/jobs.py Outdated Show resolved Hide resolved
sopel/plugins/jobs.py Outdated Show resolved Hide resolved
sopel/tools/jobs.py Outdated Show resolved Hide resolved
sopel/tools/jobs.py Outdated Show resolved Hide resolved
sopel/tools/jobs.py Show resolved Hide resolved
sopel/tools/jobs.py Outdated Show resolved Hide resolved
sopel/bot.py Show resolved Hide resolved
@Exirel
Copy link
Contributor Author

Exirel commented Jun 17, 2020

OK, there is more to say about the register/unregister situation in the bot.

  1. bot.register expects 4 parameters (callables, jobs, urls, shutdown), but bot.unregister expects just one callable and deal with it. What is that??? I think we should remove both, and I'd argue that we should not bother with deprecation cycle in this case.
  2. bot.register_* methods make sense, because they allow to register a callable, that will be transformed into some sort of object, tied to a plugin.
  3. bot.unregister_* methods don't, because what we usually want is to unregister a whole plugin, not just a single function (there should be other means to do that properly, like using rule's label, or command's name)
  4. In fact, these (un)register_* methods could (should?) be private, because the right interface should be about adding/removing a plugin, and not dealing with individual parts. I remember when working on plugin: new interface #1479 I had so much trouble making sense of the bot's interface approaching callables, jobs, urls, and so on
  5. At some point, shutdown methods shouldn't be registered - the plugin handler can do that for us
  6. Also the URL callback registration should be designed like the Rules Manager and the plugin's Scheduler, in a somewhat unified interface

It's a long process. So in this PR, I'll revert my changes on unregister, change what I did on unregister_jobs, and I'll do another PR for everything else mentioned in this comment, if that sounds good for you @dgw ?

@Exirel
Copy link
Contributor Author

Exirel commented Jun 17, 2020

@dgw also, I'll make document sopel.tools.jobs. I'll add a big important block to tell it's all internal an stuff, but if I don't do that, I'll have trouble documenting sopel.plugins.jobs.

@Exirel Exirel force-pushed the job-prevent-parallel-execution branch from cbec340 to 13efdd5 Compare June 17, 2020 15:17
@Exirel
Copy link
Contributor Author

Exirel commented Jun 17, 2020

@dgw so, you were totally right in your comments. Because I added so much docstrings, and because there was so much to fix/change/revert, I believe a "rebase" couldn't hurt in that specific case. Most of the docstrings have been updated, added, moved, or replaced, so I think you will have to re-review everything anyway.

As said earlier, I won't update the bot.unregister method again in this PR, I'll do a separate one for that, I think it's better this way. Also, I'm sorry for all the mess. I'm glad you are here doing the review, because it really makes Sopel better. Sometimes, I'm lazy, or I forget something, or I make an honest mistake. And usually, you're here to make sure it's fixed properly, and that's invaluable! ❤️

So good luck with the review, hope it won't be too difficult this time.

Copy link
Member

@dgw dgw left a comment

Choose a reason for hiding this comment

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

Fun times at grammar school. 😛

sopel/plugins/jobs.py Outdated Show resolved Hide resolved
sopel/plugins/jobs.py Outdated Show resolved Hide resolved
sopel/tools/jobs.py Outdated Show resolved Hide resolved
sopel/tools/jobs.py Outdated Show resolved Hide resolved
sopel/tools/jobs.py Outdated Show resolved Hide resolved
sopel/tools/jobs.py Outdated Show resolved Hide resolved
sopel/tools/jobs.py Outdated Show resolved Hide resolved
sopel/tools/jobs.py Outdated Show resolved Hide resolved
sopel/tools/jobs.py Outdated Show resolved Hide resolved
sopel/tools/jobs.py Outdated Show resolved Hide resolved
@Exirel Exirel requested a review from dgw June 23, 2020 12:24
@Exirel
Copy link
Contributor Author

Exirel commented Jun 23, 2020

Changes applied and fixed the docstring.

Copy link
Member

@dgw dgw left a comment

Choose a reason for hiding this comment

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

Another "Squash what you're gonna squash and we'll :shipit:"

This commit changes how the Scheduler and the Job work together, and add
a new plugins specific Scheduler:

* the new Scheduler prevents parallel execution of jobs
* jobs are created from callable
* the same interface as rules is used for jobs now (with plugin name,
  label, handler, execute method, and so on)
* jobs now manage themselves their set of interval, instead of having a
  copy of each job for each of its intervals
* sopel.tools.jobs is now part of the documentation, but are still
  marked as internal tools
* sopel.plugins.jobs is new and added to the documentation, under the
  same conditions (i.e. internal stuff)
@Exirel Exirel force-pushed the job-prevent-parallel-execution branch from a98245f to e0fd07a Compare June 24, 2020 21:14
@Exirel
Copy link
Contributor Author

Exirel commented Jun 24, 2020

Done as well.

@dgw dgw merged commit 82ad1b3 into sopel-irc:master Jun 26, 2020
@Exirel Exirel deleted the job-prevent-parallel-execution branch May 1, 2021 17:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bugfix Generally, PRs that reference (and fix) one or more issue(s) Feature High Priority
Projects
None yet
Development

Successfully merging this pull request may close these issues.

feature request: prevent parallel execution of interval
2 participants