Development of an internal social media platform with personalised dashboards for students
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

exceptions.py 4.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  1. # -*- coding: utf-8 -*-
  2. """
  3. celery.exceptions
  4. ~~~~~~~~~~~~~~~~~
  5. This module contains all exceptions used by the Celery API.
  6. """
  7. from __future__ import absolute_import
  8. import numbers
  9. from .five import string_t
  10. from billiard.exceptions import ( # noqa
  11. SoftTimeLimitExceeded, TimeLimitExceeded, WorkerLostError, Terminated,
  12. )
  13. __all__ = ['SecurityError', 'Ignore', 'QueueNotFound',
  14. 'WorkerShutdown', 'WorkerTerminate',
  15. 'ImproperlyConfigured', 'NotRegistered', 'AlreadyRegistered',
  16. 'TimeoutError', 'MaxRetriesExceededError', 'Retry',
  17. 'TaskRevokedError', 'NotConfigured', 'AlwaysEagerIgnored',
  18. 'InvalidTaskError', 'ChordError', 'CPendingDeprecationWarning',
  19. 'CDeprecationWarning', 'FixupWarning', 'DuplicateNodenameWarning',
  20. 'SoftTimeLimitExceeded', 'TimeLimitExceeded', 'WorkerLostError',
  21. 'Terminated']
  22. UNREGISTERED_FMT = """\
  23. Task of kind {0} is not registered, please make sure it's imported.\
  24. """
  25. class SecurityError(Exception):
  26. """Security related exceptions.
  27. Handle with care.
  28. """
  29. class Ignore(Exception):
  30. """A task can raise this to ignore doing state updates."""
  31. class Reject(Exception):
  32. """A task can raise this if it wants to reject/requeue the message."""
  33. def __init__(self, reason=None, requeue=False):
  34. self.reason = reason
  35. self.requeue = requeue
  36. super(Reject, self).__init__(reason, requeue)
  37. def __repr__(self):
  38. return 'reject requeue=%s: %s' % (self.requeue, self.reason)
  39. class WorkerTerminate(SystemExit):
  40. """Signals that the worker should terminate immediately."""
  41. SystemTerminate = WorkerTerminate # XXX compat
  42. class WorkerShutdown(SystemExit):
  43. """Signals that the worker should perform a warm shutdown."""
  44. class QueueNotFound(KeyError):
  45. """Task routed to a queue not in CELERY_QUEUES."""
  46. class ImproperlyConfigured(ImportError):
  47. """Celery is somehow improperly configured."""
  48. class NotRegistered(KeyError):
  49. """The task is not registered."""
  50. def __repr__(self):
  51. return UNREGISTERED_FMT.format(self)
  52. class AlreadyRegistered(Exception):
  53. """The task is already registered."""
  54. class TimeoutError(Exception):
  55. """The operation timed out."""
  56. class MaxRetriesExceededError(Exception):
  57. """The tasks max restart limit has been exceeded."""
  58. class Retry(Exception):
  59. """The task is to be retried later."""
  60. #: Optional message describing context of retry.
  61. message = None
  62. #: Exception (if any) that caused the retry to happen.
  63. exc = None
  64. #: Time of retry (ETA), either :class:`numbers.Real` or
  65. #: :class:`~datetime.datetime`.
  66. when = None
  67. def __init__(self, message=None, exc=None, when=None, **kwargs):
  68. from kombu.utils.encoding import safe_repr
  69. self.message = message
  70. if isinstance(exc, string_t):
  71. self.exc, self.excs = None, exc
  72. else:
  73. self.exc, self.excs = exc, safe_repr(exc) if exc else None
  74. self.when = when
  75. Exception.__init__(self, exc, when, **kwargs)
  76. def humanize(self):
  77. if isinstance(self.when, numbers.Real):
  78. return 'in {0.when}s'.format(self)
  79. return 'at {0.when}'.format(self)
  80. def __str__(self):
  81. if self.message:
  82. return self.message
  83. if self.excs:
  84. return 'Retry {0}: {1}'.format(self.humanize(), self.excs)
  85. return 'Retry {0}'.format(self.humanize())
  86. def __reduce__(self):
  87. return self.__class__, (self.message, self.excs, self.when)
  88. RetryTaskError = Retry # XXX compat
  89. class TaskRevokedError(Exception):
  90. """The task has been revoked, so no result available."""
  91. class NotConfigured(UserWarning):
  92. """Celery has not been configured, as no config module has been found."""
  93. class AlwaysEagerIgnored(UserWarning):
  94. """send_task ignores CELERY_ALWAYS_EAGER option"""
  95. class InvalidTaskError(Exception):
  96. """The task has invalid data or is not properly constructed."""
  97. class IncompleteStream(Exception):
  98. """Found the end of a stream of data, but the data is not yet complete."""
  99. class ChordError(Exception):
  100. """A task part of the chord raised an exception."""
  101. class CPendingDeprecationWarning(PendingDeprecationWarning):
  102. pass
  103. class CDeprecationWarning(DeprecationWarning):
  104. pass
  105. class FixupWarning(UserWarning):
  106. pass
  107. class DuplicateNodenameWarning(UserWarning):
  108. """Multiple workers are using the same nodename."""