Miksus / rocketry

Modern scheduling library for Python
https://rocketry.readthedocs.io
MIT License
3.27k stars 106 forks source link

Add tasks during runtime #200

Open carlosealves2 opened 1 year ago

carlosealves2 commented 1 year ago

Is it possible to add new tasks during the execution period? if yes, could you give me a simple example of how it can be done?

omu4 commented 1 year ago

https://rocketry.readthedocs.io/en/stable/cookbook/controlling_runtime.html#manipulating-other-tasks

from rocketry.args import Return, Session
@app.task(after_success(get_task))
def create_task(session=Session(), task_data=Return('get_task')):   
            name = "my_task"
            command = "id"            
            start_cond = "hourly"
            end_cond = running.more_than("2 hours 50 minutes")
            task_execution = "process"
            task_pre_exist = "ignore"
            session.create_task(
                command=command,
                shell=True,
                task_execution=task_execution,
                task_pre_exist=task_pre_exist,  # What happens if a task with given name already exists.
                start_cond=start_cond,
                end_cond=end_cond,
                name=name,
            )