The :pyZeebeTaskRouter
class is responsible for routing tasks to a :pyZeebeWorker
instance. This helps with organization of large projects, where you can't import the worker in each file.
from pyzeebe import ZeebeTaskRouter
router = ZeebeTaskRouter()
Creating a task with a router is the exact same process as wiht a :pyZeebeWorker
instance.
@router.task(task_type="my_task")
async def my_task(x: int):
return {"y": x + 1}
Note
The :pyZeebeTaskRouter
:pytask
decorator has all the capabities of the :pyZeebeWorker
class.
To add the router tasks to the worker we use the :pyinclude_router
method on the worker.
from my_task import router
worker.include_router(router)
Or to add multiple routers at once:
worker.include_router(router1, router2, router3, ...)
That's it!