Skip to main content

ClassBasedAutoRetryTask

This class provides a task implementation that automatically retries execution when a ValueError is encountered. It leverages built-in retry configurations, including a maximum retry limit and exponential backoff, to manage task persistence. The class tracks the number of retry attempts through the request state and returns the retry count upon successful completion.

Attributes

AttributeTypeDescription
namestring = auto_retry_class_taskThe unique identifier used to register the task within the Celery task registry.
autoretry_fortuple = (ValueError,)A tuple of exception classes that will trigger an automatic retry of the task when raised during execution.
retry_kwargsdict = {'max_retries': 1}A dictionary of configuration parameters, such as max_retries, passed to the retry method when an automatic retry is triggered.
retry_backoffboolean = trueA boolean flag or numeric value that determines if an exponential backoff delay should be applied between task retries.

Constructor

Signature

def ClassBasedAutoRetryTask() - > null

Methods


run()

@classmethod
def run() - > int

Executes the task logic, returning the current retry count if the task has been retried, or raising a ValueError to trigger the automatic retry mechanism.

Returns

TypeDescription
intThe number of times the task has been retried according to the current request state.