MCPcopy Create free account
hub / github.com/celery/celery / retry

Method retry

celery/app/task.py:816–964  ·  view source on GitHub ↗

Retry the task, adding it to the back of the queue. Example: >>> from imaginary_twitter_lib import Twitter >>> from proj.celery import app >>> @app.task(bind=True) ... def tweet(self, auth, message): ... twitter = Twitter(oaut

(self, args=None, kwargs=None, exc=None, throw=True,
              eta=None, countdown=None, max_retries=None, **options)

Source from the content-addressed store, hash-verified

814 subtask_from_request = signature_from_request # XXX compat
815
816 def retry(self, args=None, kwargs=None, exc=None, throw=True,
817 eta=None, countdown=None, max_retries=None, **options):
818 """Retry the task, adding it to the back of the queue.
819
820 Example:
821 >>> from imaginary_twitter_lib import Twitter
822 >>> from proj.celery import app
823
824 >>> @app.task(bind=True)
825 ... def tweet(self, auth, message):
826 ... twitter = Twitter(oauth=auth)
827 ... try:
828 ... twitter.post_status_update(message)
829 ... except twitter.FailWhale as exc:
830 ... # Retry in 5 minutes.
831 ... raise self.retry(countdown=60 * 5, exc=exc)
832
833 Note:
834 Although the task will never return above as `retry` raises an
835 exception to notify the worker, we use `raise` in front of the
836 retry to convey that the rest of the block won't be executed.
837
838 Arguments:
839 args (Tuple): Positional arguments to retry with.
840 kwargs (Dict): Keyword arguments to retry with.
841 exc (Exception): Custom exception to report when the max retry
842 limit has been exceeded (default:
843 :exc:`~@MaxRetriesExceededError`).
844
845 If this argument is set and retry is called while
846 an exception was raised (``sys.exc_info()`` is set)
847 it will attempt to re-raise the current exception.
848
849 If no exception was raised it will raise the ``exc``
850 argument provided.
851 countdown (float): Time in seconds to delay the retry for.
852 eta (~datetime.datetime): Explicit time and date to run the
853 retry at.
854 max_retries (int): If set, overrides the default retry limit for
855 this execution. Changes to this parameter don't propagate to
856 subsequent task retry attempts. A value of :const:`None`,
857 means "use the default", so if you want infinite retries you'd
858 have to set the :attr:`max_retries` attribute of the task to
859 :const:`None` first.
860 time_limit (int): If set, overrides the default time limit.
861 soft_time_limit (int): If set, overrides the default soft
862 time limit.
863 throw (bool): If this is :const:`False`, don't raise the
864 :exc:`~@Retry` exception, that tells the worker to mark
865 the task as being retried. Note that this means the task
866 will be marked as failed if the task raises an exception,
867 or successful if it returns after the retry call.
868 **options (Any): Extra options to pass on to :meth:`apply_async`.
869
870 Raises:
871
872 celery.exceptions.Retry:
873 To tell the worker that the task has been re-sent for retry.

Callers 15

retryFunction · 0.80
retry_unpickleableFunction · 0.80
retry_onceFunction · 0.80
retry_once_ignore_resultFunction · 0.80
retry_once_with_resultFunction · 0.80
retry_once_priorityFunction · 0.80
retry_once_headersFunction · 0.80
task_retry_then_failMethod · 0.80
retry_taskMethod · 0.80
retry_taskMethod · 0.80

Calls 8

raise_with_contextFunction · 0.90
RetryClass · 0.90
RejectClass · 0.90
signatureMethod · 0.45
popMethod · 0.45
formatMethod · 0.45
apply_asyncMethod · 0.45