docs/guide/dynamic-brokers.md
This article is for people who want to:
Taskiq allows you to set up broker instances throughout your application and register tasks for dynamic execution. However, tasks created this way won't be found by the taskiq worker command.
To define tasks and assign them to a broker, use register_task method.
In this example, the task is defined using a lambda within the main function. As the lambda is not visible outside of the main function scope, the task is not executable by taskiq worker command.
To overcome this issue, you can:
Here's an example of a dynamic worker task creation:
In this example, a named dynamic lambda task is created and registered in a broker, similar to the previous example. The difference is the creation of a new receiver coroutine for the worker task. It will listen to the new messages and execute them. The worker task will be executed in the current event loop. After exiting the scope, the worker task will get cancelled. For illustration purposes it is cancelled explicitly.
It's possible to run a scheduler in the current event loop as well: