- Notifications
You must be signed in to change notification settings - Fork5.7k
Refactor JobQueue#1981
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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Refactor JobQueue#1981
Uh oh!
There was an error while loading.Please reload this page.
Conversation
45fc55e
to2a9a5b0
Compare# Conflicts:#telegram/ext/jobqueue.py
# Was intended for interal use anyways# Fixes tests
There was a problem hiding this 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.
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
@@ -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) |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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 …
Uh oh!
There was an error while loading.Please reload this page.
telegram/ext/jobqueue.py Outdated
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) |
There was a problem hiding this comment.
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)? Thetzinfo
argument tocombine
has been added in 3.6.
Apart from that, couldn'tdatetime.datetime.now().date()
return the wrong date this way?
There was a problem hiding this comment.
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.
…python-telegram-bot into refactor-job-queue
py3.7 fail unrelated. Codacy can't check for some reason, but I ran pre-commit locally again and it's fine. |
* 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
* 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 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
* 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 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
* 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 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
Uh oh!
There was an error while loading.Please reload this page.
When ready,closes#1936 and on the flycloses#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 subclassingaps.Job
to add acontext
argument doesn't work - we'd have to patchaps.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 ourJob
class, which holds the correspondingaps.Job
.Besides the fact that rescheduling jobs must now be done directly through the
aps
interface, the main breaking change is, thatJobQueue
now can only handlepytz
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:
ConversationHandler
a bit more generous on the timing,aps
seems to like thatpytzs
everywhere in the testsEDIT:
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.test_run_repeating_first_immediate
andtest_run_repeating_first_timezone
is now also adapted for APS' needs