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

Refactor JobQueue #1981

Merged
merged 19 commits into from
Jul 10, 2020
Merged

Refactor JobQueue #1981

merged 19 commits into from
Jul 10, 2020

Conversation

Bibo-Joshi
Copy link
Member

@Bibo-Joshi Bibo-Joshi commented Jun 5, 2020

When ready, closes #1936 and on the fly closes #2004

Introduces APScheduler as 3rd party lib for scheduling tasts. The PR is not yet really polished, especially I'll need to increase coverage. But before getting started on that, I'd like to get feedback on the general design.

My main concern is the Job (already mentioned offline). Unfortunately, simply subclassing aps.Job to add a context argument doesn't work - we'd have to patch aps.Job to do that. I don't fancy that.
On the other hand, having a custom Job class with custom attributes allows to make switching to another lib a bit less breaking, if we have to do that at some point.
So I added a job attribute to our Job class, which holds the corresponding aps.Job.

Besides the fact that rescheduling jobs must now be done directly through the aps interface, the main breaking change is, that JobQueue now can only handle pytz timezones. But personally, I don't see a problem in that. Switching from fixet utc-offset timezones should be easy enough and people who need weird custom timezones should be capable enough of handling the change …

Reragrding tests:

  • test_official currently fails b/c API 4.9
  • made the timeout tests for ConversationHandler a bit more generous on the timing, aps seems to like that
  • switched to pytzs everywhere in the tests
  • besides that, I only made the existing tests run. as mentioned above, I'll need to improve coverage, once we're okay with the general design.

EDIT:
That are a lot more failing tests than I'd hoped for … Will need to check on an actual OS locally (yes, I developed on Windows, shame on me …)

EDIT 2:

  • the updater.idle() test just wasn't executed on windows … fixed it.
  • APS is a bit pickier on doing things "right now". That's one of the things, we should mention on the release notes. So I just removed test_run_repeating_first_immediate and test_run_repeating_first_timezone is now also adapted for APS' needs

@Bibo-Joshi Bibo-Joshi added this to the 13.0 milestone Jun 5, 2020
@Bibo-Joshi Bibo-Joshi requested a review from jh0ker June 5, 2020 21:28
@Bibo-Joshi Bibo-Joshi changed the base branch from master to v13 June 6, 2020 10:55
# Was intended for interal use anyways
# Fixes tests
Copy link
Member

@Poolitzer Poolitzer left a comment

Choose a reason for hiding this comment

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

Looks good to me, I love outsourcing the jobs to the APS.

telegram/ext/jobqueue.py Outdated Show resolved Hide resolved
telegram/ext/jobqueue.py Outdated Show resolved Hide resolved
@@ -742,8 +735,7 @@ def test_conversation_handler_timeout_state_context(self, cdp, bot, user1):
message.text = '/startCoding'
message.entities[0].length = len('/startCoding')
cdp.process_update(Update(update_id=0, message=message))
sleep(0.5)
cdp.job_queue.tick()
sleep(0.6)
Copy link
Member

Choose a reason for hiding this comment

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

doesnt it make sense to put this in a constant?

Copy link
Member Author

Choose a reason for hiding this comment

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

Not sure, if that's a good idea. Have one of the tests failing in the future, fiddle with the constant, suddenly everthing fails and it's not obvious why …

tests/test_jobqueue.py Outdated Show resolved Hide resolved
return self._tz_now() + time
if isinstance(time, datetime.time):
dt = datetime.datetime.combine(datetime.datetime.now().date(), time,
tzinfo=time.tzinfo or self.scheduler.timezone)
Copy link
Member

@jh0ker jh0ker Jun 24, 2020

Choose a reason for hiding this comment

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

I don't know about this... Are we dropping 3.5 support (or did we already)? The tzinfo argument to combine has been added in 3.6.

Apart from that, couldn't datetime.datetime.now().date() return the wrong date this way?

Copy link
Member Author

Choose a reason for hiding this comment

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

Uh, you're right. Couldn't tell, because TG messed up our tests again …. But we're dropping py3.5 an #1920 anyway, so we might as well do here.

And right once more. I'll add it back.

@Bibo-Joshi
Copy link
Member Author

py3.7 fail unrelated. Codacy can't check for some reason, but I ran pre-commit locally again and it's fine.
As discussed offline we'll probably need to do some clean up after release anyway, but we need people to actaully use the new JobQueue for that. Merging.

@Bibo-Joshi Bibo-Joshi merged commit 088e608 into v13 Jul 10, 2020
@Bibo-Joshi Bibo-Joshi deleted the refactor-job-queue branch July 10, 2020 11:11
Bibo-Joshi added a commit that referenced this pull request Jul 14, 2020
* First go on refactoring JobQueue

* Temporarily enable tests for the v13 branch

* Work on tests

* Temporarily enable tests for the v13 branch

* Increase coverage

* Remove JobQueue.tick()

# Was intended for interal use anyways
# Fixes tests

* Address review

* Temporarily enable tests for the v13 branch

* Address review

* Dispatch errors

* Fix handling of job_kwargs

* Remove possibility to pass a Bot to JobQueue
@Bibo-Joshi Bibo-Joshi mentioned this pull request Jul 18, 2020
Bibo-Joshi added a commit that referenced this pull request Jul 19, 2020
* First go on refactoring JobQueue

* Temporarily enable tests for the v13 branch

* Work on tests

* Temporarily enable tests for the v13 branch

* Increase coverage

* Remove JobQueue.tick()

# Was intended for interal use anyways
# Fixes tests

* Address review

* Temporarily enable tests for the v13 branch

* Address review

* Dispatch errors

* Fix handling of job_kwargs

* Remove possibility to pass a Bot to JobQueue
Bibo-Joshi added a commit that referenced this pull request Jul 19, 2020
* Refactor handling of `default_quote`

* Make it a breaking change

* Pickle a bots defaults

* Temporarily enable tests for the v13 branch

* Temporarily enable tests for the v13 branch

* Refactor handling of kwargs in Bot methods (#1924)

* Unify kwargs handling in Bot methods

* Remove Request.get, make api_kwargs an explicit argument, move note to head of Bot class

* Fix test_official

* Update get_file methods

* Refactor JobQueue (#1981)

* First go on refactoring JobQueue

* Temporarily enable tests for the v13 branch

* Work on tests

* Temporarily enable tests for the v13 branch

* Increase coverage

* Remove JobQueue.tick()

# Was intended for interal use anyways
# Fixes tests

* Address review

* Temporarily enable tests for the v13 branch

* Address review

* Dispatch errors

* Fix handling of job_kwargs

* Remove possibility to pass a Bot to JobQueue

* Refactor persistence of Bot instances (#1994)

* Refactor persistence of bots

* User BP.set_bot in Dispatcher

* Temporarily enable tests for the v13 branch

* Add documentation

* Add warning to Updater for passing both defaults and bot

* Address review

* Fix test
Bibo-Joshi added a commit that referenced this pull request Aug 13, 2020
* First go on refactoring JobQueue

* Temporarily enable tests for the v13 branch

* Work on tests

* Temporarily enable tests for the v13 branch

* Increase coverage

* Remove JobQueue.tick()

# Was intended for interal use anyways
# Fixes tests

* Address review

* Temporarily enable tests for the v13 branch

* Address review

* Dispatch errors

* Fix handling of job_kwargs

* Remove possibility to pass a Bot to JobQueue
Bibo-Joshi added a commit that referenced this pull request Aug 13, 2020
* Refactor handling of `default_quote`

* Make it a breaking change

* Pickle a bots defaults

* Temporarily enable tests for the v13 branch

* Temporarily enable tests for the v13 branch

* Refactor handling of kwargs in Bot methods (#1924)

* Unify kwargs handling in Bot methods

* Remove Request.get, make api_kwargs an explicit argument, move note to head of Bot class

* Fix test_official

* Update get_file methods

* Refactor JobQueue (#1981)

* First go on refactoring JobQueue

* Temporarily enable tests for the v13 branch

* Work on tests

* Temporarily enable tests for the v13 branch

* Increase coverage

* Remove JobQueue.tick()

# Was intended for interal use anyways
# Fixes tests

* Address review

* Temporarily enable tests for the v13 branch

* Address review

* Dispatch errors

* Fix handling of job_kwargs

* Remove possibility to pass a Bot to JobQueue

* Refactor persistence of Bot instances (#1994)

* Refactor persistence of bots

* User BP.set_bot in Dispatcher

* Temporarily enable tests for the v13 branch

* Add documentation

* Add warning to Updater for passing both defaults and bot

* Address review

* Fix test
Bibo-Joshi added a commit that referenced this pull request Aug 16, 2020
* First go on refactoring JobQueue

* Temporarily enable tests for the v13 branch

* Work on tests

* Temporarily enable tests for the v13 branch

* Increase coverage

* Remove JobQueue.tick()

# Was intended for interal use anyways
# Fixes tests

* Address review

* Temporarily enable tests for the v13 branch

* Address review

* Dispatch errors

* Fix handling of job_kwargs

* Remove possibility to pass a Bot to JobQueue
Bibo-Joshi added a commit that referenced this pull request Aug 16, 2020
* Refactor handling of `default_quote`

* Make it a breaking change

* Pickle a bots defaults

* Temporarily enable tests for the v13 branch

* Temporarily enable tests for the v13 branch

* Refactor handling of kwargs in Bot methods (#1924)

* Unify kwargs handling in Bot methods

* Remove Request.get, make api_kwargs an explicit argument, move note to head of Bot class

* Fix test_official

* Update get_file methods

* Refactor JobQueue (#1981)

* First go on refactoring JobQueue

* Temporarily enable tests for the v13 branch

* Work on tests

* Temporarily enable tests for the v13 branch

* Increase coverage

* Remove JobQueue.tick()

# Was intended for interal use anyways
# Fixes tests

* Address review

* Temporarily enable tests for the v13 branch

* Address review

* Dispatch errors

* Fix handling of job_kwargs

* Remove possibility to pass a Bot to JobQueue

* Refactor persistence of Bot instances (#1994)

* Refactor persistence of bots

* User BP.set_bot in Dispatcher

* Temporarily enable tests for the v13 branch

* Add documentation

* Add warning to Updater for passing both defaults and bot

* Address review

* Fix test
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Aug 17, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Refactor JobQueue
3 participants