graph LR
Middleware["Middleware"]
SmartRetryMiddleware["SmartRetryMiddleware"]
SmartRetryMiddleware -- "inherits from" --> Middleware
The Middleware System in taskiq provides a flexible mechanism to intercept and modify the task lifecycle at various stages. It adheres to the "Pluggable Architecture" pattern, allowing developers to inject custom logic before, during, or after task processing.
This is the abstract base class (taskiq.abc.middleware.Middleware) that defines the contract for all middleware components. It specifies a set of asynchronous methods (hooks) such as on_before_send, on_after_send, on_before_process, on_after_process, and on_error. These hooks are strategically placed to allow interception of different phases of a task's lifecycle, enabling custom logic to be executed at specific points.
Related Classes/Methods:
taskiq.abc.middleware.Middlewaretaskiq.abc.middleware.Middleware:on_before_sendtaskiq.abc.middleware.Middleware:on_after_sendtaskiq.abc.middleware.Middleware:on_before_processtaskiq.abc.middleware.Middleware:on_after_processtaskiq.abc.middleware.Middleware:on_error
A concrete implementation of the Middleware abstract base class (taskiq.middlewares.smart_retry_middleware.SmartRetryMiddleware). Its specific responsibility is to provide a "smart retry" mechanism for tasks that fail during execution. This typically involves catching exceptions within its on_error hook, determining if a retry is appropriate based on configured criteria (e.g., number of attempts, specific error types), and re-queuing the task for a subsequent execution attempt. This component directly contributes to the system's robustness and fault tolerance.
Related Classes/Methods: