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)
| 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. |