-
-
Notifications
You must be signed in to change notification settings - Fork 108
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
ENH Parameterise scheduling interval and easily add/remove tasks #75
Comments
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 The session object ( session = app.session
# Get a task based on its name:
task = session["my_task"]
# Remove task
session.tasks.remove(task) For adding, it's recommended to use the from rocketry.tasks import FuncTask
task = FuncTask(func=my_task_func, start_cond="every 10 minutes")
session.add_task(task) |
Ah you are right, that is indeed exactly what I was looking for. I guess that is what the documentation is describing here when it mentions:
I did not understand the start condition from that, but I now see that I can pass it indeed with Indeed it might make sense to have a |
Yep, the first argument is actually the But back to the issue. Actually, I now added So these should now work from rocketry.args import Session
@app.task()
def manipulate(session=Session()):
session.create_task(start_cond="daily", name="a task", func=do_things)
session.remove_task("a task") Note that this does not accept the start condition as a positional argument but as a keyword argument. The I hope this helps to reach your goal and thanks again for the suggestion! Does this answer your problem or do you feel I missed something? It seems I forgot to write about these in the documentation. I'll keep the issue open until that's done though. |
I think that is quite a straight forward and elegant solution. It also indeed covers my question perfectly and I think this will allow me to implement it in the tool I had this envisioned for, thank you! Yes I can imagine. Sometimes it feels like you can write 20 lines of documentation for every line of code... :) |
I had exactly the same question and use case - but saw the reference to create_task in the release notes and got my use case working before I saw this issue :) But agreed - great to have a section on dynamic ( non decorator based ) task creation. and great work on the project so far - I'm finding it very useful, especially with the async support, easy integration with FastAPI etc. |
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). |
I 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.
The text was updated successfully, but these errors were encountered: