Skip to content

Commit 88dbe3a

Browse files
committed
Merge branch 'release/0.4.0'
2 parents 318b25b + 5409c09 commit 88dbe3a

37 files changed

+1127
-663
lines changed

.flake8

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
[flake8]
2-
max-complexity = 6
2+
max-complexity = 7
33
inline-quotes = double
44
max-line-length = 88
55
extend-ignore = E203
@@ -90,6 +90,8 @@ ignore =
9090
N802,
9191
; Do not perform function calls in argument defaults.
9292
B008,
93+
; Found too many public instance attributes
94+
WPS230,
9395

9496
; all init files
9597
__init__.py:

.github/workflows/test.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name: Testing taskiq
22

3-
on: push
3+
on: [pull_request]
44

55
jobs:
66
lint:

docs/available-components/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,6 @@ dir:
99
In this section, you can find a list of officially supported plugins for the taskiq.
1010

1111
- [Available brokers](./brokers.md)
12+
- [Available middlewares](./middlewares.md)
1213
- [Available result backends](./result-backends.md)
1314
- [Available schedule sources](./schedule-sources.md)
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
---
2+
order: 5
3+
---
4+
5+
# Available middlewares
6+
7+
Middlewares allow you to execute code when specific event occurs.
8+
Taskiq has several default middlewares.
9+
10+
### Simple retry middleware
11+
12+
This middleware allows you to restart functions on errors. If exception was raised during task execution,
13+
the task would be resent with same parameters.
14+
15+
To enable this middleware, add it to the list of middlewares for a broker.
16+
17+
```python
18+
from taskiq import SimpleRetryMiddleware
19+
20+
broker = ...
21+
22+
broker.add_middlewares(SimpleRetryMiddleware(default_retry_count=3))
23+
```
24+
25+
After that you can add a label to task that you want to restart on error.
26+
27+
```python
28+
29+
@broker.task(retry_on_error=True, max_retries=20)
30+
async def test():
31+
raise Exception("AAAAA!")
32+
33+
```
34+
35+
`retry_on_error` enables retries for a task. `max_retries` is the maximum number of times,.
36+
37+
### Prometheus middleware
38+
39+
You can enable prometheus metrics for workers by adding PrometheusMiddleware.
40+
To do so, you need to install `prometheus_client` package or you can install metrics extras for taskiq.
41+
42+
::: tabs
43+
44+
45+
@tab only prometheus
46+
47+
```bash
48+
pip install "prometheus_client"
49+
```
50+
51+
@tab taskiq with extras
52+
53+
```bash
54+
pip install "taskiq[metrics]"
55+
```
56+
57+
:::
58+
59+
60+
```python
61+
from taskiq import PrometheusMiddleware
62+
63+
broker = ...
64+
65+
broker.add_middlewares(PrometheusMiddleware(server_addr="0.0.0.0", server_port=9000))
66+
```
67+
68+
After that, metrics will be available at port 9000. Of course, this parameter can be configured.
69+
If you have other metrics, they'll be shown as well.

docs/examples/extending/broker.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,12 @@ async def shutdown(self) -> None:
2525
return await super().shutdown()
2626

2727
async def kick(self, message: BrokerMessage) -> None:
28-
# Send a message.
28+
# Send a message.message.
2929
pass
3030

31-
async def listen(self) -> AsyncGenerator[BrokerMessage, None]:
31+
async def listen(self) -> AsyncGenerator[bytes, None]:
3232
while True:
3333
# Get new message.
34-
new_message: BrokerMessage = ... # type: ignore
34+
new_message: bytes = ... # type: ignore
3535
# Yield it!
3636
yield new_message

docs/extending-taskiq/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ All abstract classes can be found in `taskiq.abc` package.
1313
## Contents:
1414

1515
- [Brokers](./broker.md)
16-
- [Brokers](./broker.md)
16+
- [Middlewares](./middleware.md)
1717
- [Result backends](./resutl-backend.md)
1818
- [CLI](./cli.md)
1919
- [Schedule sources](./schedule-sources.md)

docs/extending-taskiq/broker.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,20 @@ Here is a template for new brokers:
1111

1212
@[code python](../examples/extending/broker.py)
1313

14+
15+
# About kick and listen
16+
17+
The `kick` method takes a `BrokerMessage` as a parameter. The `BrokerMessage` class is a handy helper class for brokers. You can use information from the BrokerMessage to alter the delivery method.
18+
19+
::: warning "cool warning!"
20+
21+
As a broker developer, please send only raw bytes from the `message` field of a BrokerMessage if possible. Serializing it to the string may result in a problem if message bytes are not utf-8 compatible.
22+
23+
:::
24+
25+
26+
The `listen` method should yield raw bytes that were sent over the network.
27+
1428
## Conventions
1529

1630
For brokers, we have several conventions. It's good if your broker implements them.

docs/guide/cli.md

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,10 +47,29 @@ To disable this pass the `--no-parse` option to the taskiq.
4747
### Hot reload
4848

4949
This is annoying to restart workers every time you modify tasks. That's why taskiq supports hot-reload.
50-
To enable this option simply pass the `--reload` or `-r` option to taskiq CLI.
50+
Reload is unavailable by default. To enable this feature install taskiq with `reload` extra.
5151

52-
Also this option supports `.gitignore` files. If you have such files in your directory. It won't reload worker
53-
if you ignore file's contents. To disable this functionality pass `--do-not-use-gitignore` option.
52+
::: tabs
53+
54+
55+
@tab pip
56+
57+
```bash:no-line-numbers
58+
pip install "taskiq[reload]"
59+
```
60+
61+
@tab poetry
62+
63+
```bash:no-line-numbers
64+
poetry add taskiq -E reload
65+
```
66+
67+
:::
68+
69+
To enable this option simply pass the `--reload` or `-r` option to worker taskiq CLI.
70+
71+
Also this option supports `.gitignore` files. If you have such file in your directory, it won't reload worker
72+
when you modify ignored files. To disable this functionality pass `--do-not-use-gitignore` option.
5473

5574
## Scheduler
5675

0 commit comments

Comments
 (0)