- Notifications
You must be signed in to change notification settings - Fork5.7k
Description
Just asJobQueue.run_repeating
takes afirst
optional keyword argument, that specifies the first time a job should be run (as adatetime.datetime
object, for example), I believe it would be convenient to add alast
optional keyword argument that specified, if relevant, the last time a job should be run.
Use cases
I can think of a few use cases, but I'm sure there are more. For example, suppose the bot is part of a game, during which it has to send regular updates (by using aJob
). Suppose the game lasts a fixed amount of time, which set prior to its start; say, 1 hour. Then, by specifying thelast
keyword argument, the bot programmer could set the "regular updates job" to end when the game ends.
Current alternative
A workaround I have been using is to specify a separaterun_once
job that will run theschedule_removal
method on the job at the desired time. A better way is to check inside the job's callback, and remove the job from there usingjob.schedule_removal()
.
In either case, I find these solutions to be, if not cumbersome, inelegant, compared to having a much simpler-to-use and elegant dedicated feature.
A proposed implementation can be found in#1345.