Skip to content

last kwarg for JobQueue.run_repeating method #1333

@plammens

Description

@plammens

Just as JobQueue.run_repeating takes a first optional keyword argument, that specifies the first time a job should be run (as a datetime.datetime object, for example), I believe it would be convenient to add a last 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 a Job). Suppose the game lasts a fixed amount of time, which set prior to its start; say, 1 hour. Then, by specifying the last 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 separate run_once job that will run the schedule_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 using job.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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions