Skip to content

Latest commit

 

History

History
53 lines (29 loc) · 1.15 KB

worker_taskrouter.rst

File metadata and controls

53 lines (29 loc) · 1.15 KB

Task Router

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.

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 :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.

Merge Router tasks to a worker

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!