Task Router

The ZeebeTaskRouter class is responsible for routing tasks to a ZeebeWorker instance. This helps with organization of large projects, where you can’t import the worker in each file.

Create a Router

from pyzeebe import ZeebeTaskRouter

router = ZeebeTaskRouter()

Create a task with a Router

Creating a task with a router is the exact same process as wiht a ZeebeWorker instance.

@router.task(task_type="my_task")
async def my_task(x: int):
    return {"y": x + 1}

Note

The ZeebeTaskRouter task() decorator has all the capabities of the ZeebeWorker class.

Merge Router tasks to a worker

To add the router tasks to the worker we use the include_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!