Skip to content

Latest commit

 

History

History
32 lines (20 loc) · 861 Bytes

middleware.md

File metadata and controls

32 lines (20 loc) · 861 Bytes
order 2

Middlewares

Middlewares are super helpful. You can inject some code before or after task's execution.

Middlewares must implement taskiq.abc.middleware.TaskiqMiddleware abstract class. Every method of a middleware can be either sync or async. Taskiq will execute it as you expect.

For example:

::: tabs

@tab sync

@code python

@tab async

@code python

:::

Also, middlewares always have reference to the current broker in self.broker field. If you want to kick a message during the execution of some middleware hooks, you may use self.broker to do so.

Taskiq-pipelines uses middlewares to call next tasks.