cowbird.request_task ==================== .. py:module:: cowbird.request_task Exceptions ---------- .. autoapisummary:: cowbird.request_task.AbortException Classes ------- .. autoapisummary:: cowbird.request_task.RequestTask Module Contents --------------- .. py:exception:: AbortException Bases: :py:obj:`Exception` Exception raised when the chain must be interrupted. Initialize self. See help(type(self)) for accurate signature. .. py:class:: RequestTask Bases: :py:obj:`celery.app.task.Task`, :py:obj:`abc.ABC` Celery base task that should be used to handle API requests. Using this class will set the following Task configuration : - auto-retry for every RequestException - backoff and jitter strategy There is also an abort_chain function to stop the chain of requests in case of an unrecoverable event To use this class simply decorate your asynchronous function like this: .. code-block:: python from celery import shared_task @shared_task(bind=True, base=RequestTask) def function_name(self, any, wanted, parameters): pass # function operations Parameter ``bind=True`` will provide the self argument to the function which is the celery Task (not required). Parameter ``base=RequestTask`` will instantiate a RequestTask rather than a base celery Task as the self object. .. py:attribute:: autoretry_for :type: Tuple[Exception] Exceptions that are accepted as valid raising cases to attempt request retry. .. py:attribute:: retry_backoff :value: True Enable backoff strategy during request retry upon known raised exception. .. py:attribute:: retry_backoff_max :value: 600 Maximum backoff delay permitted using request retry. Retries are abandoned if this delay is reached. .. py:attribute:: retry_jitter :value: True Enable jitter strategy during request retry upon known raised exception. .. py:attribute:: retry_kwargs Additional parameters to be passed down to requests for retry control. .. py:method:: abort_chain() -> None Calling this function from a task will prevent any downstream tasks to be run after it.