Skip to content

Commit d6a1726

Browse files
committed
Make dynamic-brokers.md easier to read
1 parent 0e92f91 commit d6a1726

File tree

3 files changed

+17
-21
lines changed

3 files changed

+17
-21
lines changed

docs/examples/dynamics/receiver.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ async def main() -> None:
1717
task_name="dyn_task",
1818
)
1919

20-
# now we can send it.
20+
# Now we can send it.
2121
await dyn_task.kiq(x=1)
2222

2323
await asyncio.sleep(2)

docs/examples/dynamics/scheduler.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ async def main() -> None:
3232
# We create scheduler after the task declaration,
3333
# so we don't have to wait a minute before it gets to the task.
3434
# However, defining a scheduler before the task declaration is also possible.
35-
# but we have to wait till it gets to task execution for the second time.
35+
# But we have to wait till it gets to task execution for the second time.
3636
worker_task = asyncio.create_task(run_receiver_task(dyn_broker))
3737
scheduler_task = asyncio.create_task(run_scheduler_task(dyn_scheduler))
3838

docs/guide/dynamic-brokers.md

Lines changed: 15 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -3,35 +3,31 @@ title: Dynamic Environments
33
order: 9
44
---
55

6-
This article is for all the people who want to dynamically create brokers, register tasks, and run them inside their code. Or maybe implement more complex logic.
6+
This article is for people who want to:
77

8-
The Taskiq allows you to create broker instances in all parts of your application. You
9-
can register tasks dynamically and run them. But when tasks are created dynamically,
10-
the `taskiq worker` command won't be able to find them.
8+
* Create brokers dynamically.
9+
* Register tasks, and run them inside their code.
10+
* Implement more complex logic.
1111

12-
To define tasks and assign them to broker, use `register_task` method.
12+
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.
13+
14+
To define tasks and assign them to a broker, use `register_task` method.
1315

1416
@[code python](../examples/dynamics/broker.py)
1517

16-
The problem with this code is that if we run the `taskiq worker` command, it won't be able
17-
to execute our tasks. Because lambdas are created within the `main` function and they
18-
are not visible outside of it.
18+
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.
19+
20+
To overcome this issue, you can:
1921

20-
To surpass this issue, we need to create a dynamic worker task within the current loop.
21-
Or, we can create a code that can listen to our brokers and have all information about dynamic
22-
functions.
22+
* Create a dynamic worker task within the current event loop.
23+
* Implement your own broker listener with the information about all of your tasks.
2324

24-
Here I won't be showing how to create your own CLI command, but I'll show you how to create
25-
a dynamic worker within the current loop.
25+
Here's an example of a dynamic worker task creation:
2626

2727
@[code python](../examples/dynamics/receiver.py)
2828

29-
Here we define a dynamic lambda task with some name, assign it to broker, as we did before.
30-
The only difference is that we start our receiver coroutine, that will listen to the new
31-
messages and execute them. Receiver task will be executed in the current loop, and when main function
32-
exits, the receriver task is canceled. But for illustration purpose, I canceled it manually.
29+
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.
3330

34-
Sometimes you need to run not only receiver, but a scheduler as well. You can do it, by using
35-
another function that also can work within the current loop.
31+
It's possible to run a scheduler in the current event loop as well:
3632

3733
@[code python](../examples/dynamics/scheduler.py)

0 commit comments

Comments
 (0)