Concurrent tasks with dependencies #233
-
I'd like to run several tasks with specific dynamic sequences. The dependencies can change, depending on the argument to I think I can use I was also thinking that I could run all the steps with |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
TaskiqDepends has support for kwargs, but it cannot be used for dynamic dependency generation and you cannot use task arguments as dependency argument. Maybe this can be a good feature. I created an issue, but it's hard implement, so I cannot provide you with due date. For now, you can either create multiple tasks, or call your function at the beginning. Here's simple example of using kwargs in import asyncio
from taskiq import InMemoryBroker, TaskiqDepends
broker = InMemoryBroker()
async def dependency(sleep_time: float) -> float:
await asyncio.sleep(sleep_time)
return sleep_time
@broker.task
async def short_sleep(sleept: float = TaskiqDepends(dependency, kwargs={"sleep_time": 0.5})):
print(f"short_sleep: {sleept}")
@broker.task
async def long_sleep(sleept: float = TaskiqDepends(dependency, kwargs={"sleep_time": 2.0})):
print(f"long_sleep: {sleept}")
async def main():
await short_sleep.kiq()
t2 = await long_sleep.kiq()
await t2.wait_result()
if __name__ == "__main__":
asyncio.run(main()) Regarding About dependencies and all, maybe, if you were thinking not about dependencies, but tasks, maybe https://github.com/taskiq-python/taskiq-pipelines might be a good fit in your situation. |
Beta Was this translation helpful? Give feedback.
TaskiqDepends has support for kwargs, but it cannot be used for dynamic dependency generation and you cannot use task arguments as dependency argument. Maybe this can be a good feature. I created an issue, but it's hard implement, so I cannot provide you with due date.
For now, you can either create multiple tasks, or call your function at the beginning.
Here's simple example of using kwargs in
TaskiqDepends
. As you can see, it's only simple static values.