ENH Parameterise scheduling interval and easily add/remove tasks
See original GitHub issueI really like the potential of this library. I might be misinterpreting the documentation, but I believe this feature is not (easily) available.
Is your feature request related to a problem? Please describe. The tasks are not known beforehand/statics. I would like to be able to dynamically create tasks and add them to the scheduler (both before running and while running).
Describe the solution you’d like Something along the lines of:
app.add_task(name="my_task",interval="every 10 minutes",callback=my_fun)
app.remove_task(name="my_task")
Describe alternatives you’ve considered I have tried messing with the Session() and Task() things, as from the documentation it hints that you can create tasks this way. However, I did not understand from the documentation how this would work other than manipulating existing tasks.
Additional context I am writing a CLI app where I would like the load the schedule from a configuration file and also allow the user to dynamically add tasks to the schedule.
Issue Analytics
- State:
- Created a year ago
- Reactions:2
- Comments:6 (3 by maintainers)
Thanks a lot, this means a lot to me and comments like yours keep me working on the project 😃 I think things should be made easy, like FastAPI makes it easy to create APIs, and I have a feeling this will make a lot of other things easy as well. There is a lot this framework could do now and there is a lot this could do in the future.
By the way, I hope you don’t mind if I change the label as documentation (as that’s the missing part).
This is totally possible to do at the moment but after thinking a bit, I think we should indeed have methods for at least removing tasks. There is an
add_task
method and a task can be fetched from the session as well using getitem. Good point though, we should make this more intuitive.The session object (
app.session
or use the dynamic argument,rocketry.args.Session
) contains an attribute.tasks
that is a set. This set contains the tasks and it is the single source of truth for them in scheduling session. You are free to add tasks or remove them like:For adding, it’s recommended to use the
session.add_task
as that checks whether a task already exists with the same name: