question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

ENH Parameterise scheduling interval and easily add/remove tasks

See original GitHub issue

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.

Issue Analytics

  • State:open
  • Created a year ago
  • Reactions:2
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

4reactions
Miksuscommented, Aug 18, 2022

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).

2reactions
Miksuscommented, Aug 12, 2022

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:

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 session.add_task as that checks whether a task already exists with the same name:

from rocketry.tasks import FuncTask
task = FuncTask(func=my_task_func, start_cond="every 10 minutes")
session.add_task(task)
Read more comments on GitHub >

github_iconTop Results From Across the Web

Reports Scheduler
The report automatically generates data according to the schedule. This functionality is accessed by selecting Miscellaneous>Reports Scheduler. All available ...
Read more >
Db2 11 - Administration - Scheduling administrative tasks - IBM
The administrative task scheduler is based on scheduled tasks. Db2 users can add, remove, and list scheduled tasks that are executed at planned...
Read more >
About Tasks in the Basic Scheduling Tool
You can complete the available task options, such as specifying parameter values, ... Caution: Be sure that you set the schedule interval to...
Read more >
System Monitoring - SAP Support Portal
System Monitoring is based on automated checks in regular time intervals in the four ... Within the configuration, you can easily add/remove/change metrics, ......
Read more >
Configuring a schedule and advanced options
task manually or schedule it to run at a specific time or interval. ... task contains parameters, you can use parameter values from...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found