Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions docs/available-components/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,6 @@ dir:
In this section, you can find a list of officially supported plugins for the taskiq.

- [Available brokers](./brokers.md)
- [Available middlewares](./middlewares.md)
- [Available result backends](./result-backends.md)
- [Available schedule sources](./schedule-sources.md)
69 changes: 69 additions & 0 deletions docs/available-components/middlewares.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
---
order: 5
---

# Available middlewares

Middlewares allow you to execute code when specific event occurs.
Taskiq has several default middlewares.

### Simple retry middleware

This middleware allows you to restart functions on errors. If exception was raised during task execution,
the task would be resent with same parameters.

To enable this middleware, add it to the list of middlewares for a broker.

```python
from taskiq import SimpleRetryMiddleware

broker = ...

broker.add_middlewares(SimpleRetryMiddleware(default_retry_count=3))
```

After that you can add a label to task that you want to restart on error.

```python

@broker.task(retry_on_error=True, max_retries=20)
async def test():
raise Exception("AAAAA!")

```

`retry_on_error` enables retries for a task. `max_retries` is the maximum number of times,.

### Prometheus middleware

You can enable prometheus metrics for workers by adding PrometheusMiddleware.
To do so, you need to install `prometheus_client` package or you can install metrics extras for taskiq.

::: tabs


@tab only prometheus

```bash
pip install "prometheus_client"
```

@tab taskiq with extras

```bash
pip install "taskiq[metrics]"
```

:::


```python
from taskiq import PrometheusMiddleware

broker = ...

broker.add_middlewares(PrometheusMiddleware(server_addr="0.0.0.0", server_port=9000))
```

After that, metrics will be available at port 9000. Of course, this parameter can be configured.
If you have other metrics, they'll be shown as well.
2 changes: 1 addition & 1 deletion docs/extending-taskiq/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ All abstract classes can be found in `taskiq.abc` package.
## Contents:

- [Brokers](./broker.md)
- [Brokers](./broker.md)
- [Middlewares](./middleware.md)
- [Result backends](./resutl-backend.md)
- [CLI](./cli.md)
- [Schedule sources](./schedule-sources.md)
Loading