rocketry
rocketry copied to clipboard
ENH: Allow running same task parallel
Is your feature request related to a problem? Please describe. Currently, a task can run only once at a time. It does not support launching the same task simultaneously.
Describe the solution you'd like Something like this:
@app.task(multilaunch=True)
def do_things(arg):
print("Doing", arg)
time.sleep(2)
print("Did", arg)
If it was called like this:
task.run(arg="1")
task.run(arg="2")
This should print:
Doing 1
Doing 2
Did 1
Did 2
Currently, Rocketry checks whether the task is already running before running it. And it will block second run if it was running.
Describe alternatives you've considered Create duplicate tasks with different names.
Additional context By default this should be not permitted as the logs may become a mess.
like this?
from functools import partial
async def do_things(arg):
print("Doing", arg)
time.sleep(2)
print("Did", arg)
t1 = app.task("every 10 seconds", name="t1")(partial(do_things, arg=1))
t2 = app.task("every 15 seconds", name="t2")(partial(do_things, arg=2))
logger.info(f'{t1=}')
logger.info(f'{t2=}')
app.run()