Skip to content

Commit e0b4b05

Browse files
committed
Merge branch 'release/0.9.2'
2 parents 0e92f91 + 66da7fe commit e0b4b05

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+805
-1281
lines changed

.github/workflows/test.yml

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,8 @@ jobs:
88
matrix:
99
cmd:
1010
- black
11-
- flake8
12-
- isort
11+
- ruff
1312
- mypy
14-
- autoflake
1513
runs-on: ubuntu-latest
1614
steps:
1715
- uses: actions/checkout@v2

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,3 +168,6 @@ node_modules
168168

169169
# macOS
170170
.DS_Store
171+
172+
# Ruff
173+
.ruff_cache/

.pre-commit-config.yaml

Lines changed: 10 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ repos:
1212
- repo: https://github.com/asottile/add-trailing-comma
1313
rev: v2.1.0
1414
hooks:
15-
- id: add-trailing-comma
15+
- id: add-trailing-comma
1616

1717
- repo: local
1818
hooks:
@@ -22,35 +22,19 @@ repos:
2222
language: system
2323
types: [python]
2424

25-
- id: autoflake
26-
name: autoflake
27-
entry: poetry run autoflake
28-
language: system
29-
types: [ python ]
30-
args: [ --in-place, --remove-all-unused-imports, --remove-duplicate-keys ]
31-
32-
- id: isort
33-
name: isort
34-
entry: poetry run isort
35-
language: system
36-
types: [ python ]
37-
38-
- id: flake8
39-
name: Check with Flake8
40-
entry: poetry run flake8
25+
- id: ruff
26+
name: Run ruff lints
27+
entry: poetry run ruff
4128
language: system
4229
pass_filenames: false
43-
types: [ python ]
44-
args: [--count, taskiq]
30+
types: [python]
31+
args:
32+
- "--fix"
33+
- "taskiq"
34+
- "tests"
4535

4636
- id: mypy
4737
name: Validate types with MyPy
4838
entry: poetry run mypy
4939
language: system
50-
types: [ python ]
51-
52-
- id: yesqa
53-
name: Remove usless noqa
54-
entry: poetry run yesqa
55-
language: system
56-
types: [ python ]
40+
types: [python]

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)