exceptions.py 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  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. from billiard.exceptions import ( # noqa
  9. SoftTimeLimitExceeded, TimeLimitExceeded, WorkerLostError,
  10. )
  11. UNREGISTERED_FMT = """\
  12. Task of kind %s is not registered, please make sure it's imported.\
  13. """
  14. class SecurityError(Exception):
  15. """Security related exceptions.
  16. Handle with care.
  17. """
  18. class SystemTerminate(SystemExit):
  19. """Signals that the worker should terminate."""
  20. class QueueNotFound(KeyError):
  21. """Task routed to a queue not in CELERY_QUEUES."""
  22. class ImproperlyConfigured(ImportError):
  23. """Celery is somehow improperly configured."""
  24. class NotRegistered(KeyError):
  25. """The task is not registered."""
  26. def __repr__(self):
  27. return UNREGISTERED_FMT % str(self)
  28. class AlreadyRegistered(Exception):
  29. """The task is already registered."""
  30. class TimeoutError(Exception):
  31. """The operation timed out."""
  32. class MaxRetriesExceededError(Exception):
  33. """The tasks max restart limit has been exceeded."""
  34. class RetryTaskError(Exception):
  35. """The task is to be retried later."""
  36. def __init__(self, message=None, exc=None, when=None, **kwargs):
  37. from kombu.utils.encoding import safe_repr
  38. self.message = message
  39. if isinstance(exc, basestring):
  40. self.exc, self.excs = None, exc
  41. else:
  42. self.exc, self.excs = exc, safe_repr(exc) if exc else None
  43. self.when = when
  44. Exception.__init__(self, exc, when, **kwargs)
  45. def humanize(self):
  46. if isinstance(self.when, int):
  47. return 'in %ss' % self.when
  48. return 'at %s' % (self.when, )
  49. def __str__(self):
  50. if self.message:
  51. return self.message
  52. if self.excs:
  53. return 'Retry %s: %r' % (self.humanize(), self.excs)
  54. return 'Retry %s' % self.humanize()
  55. def __reduce__(self):
  56. return self.__class__, (self.message, self.excs, self.when)
  57. class TaskRevokedError(Exception):
  58. """The task has been revoked, so no result available."""
  59. class NotConfigured(UserWarning):
  60. """Celery has not been configured, as no config module has been found."""
  61. class AlwaysEagerIgnored(UserWarning):
  62. """send_task ignores CELERY_ALWAYS_EAGER option"""
  63. class InvalidTaskError(Exception):
  64. """The task has invalid data or is not properly constructed."""
  65. class CPendingDeprecationWarning(PendingDeprecationWarning):
  66. pass
  67. class CDeprecationWarning(DeprecationWarning):
  68. pass
  69. class IncompleteStream(Exception):
  70. """Found the end of a stream of data, but the data is not yet complete."""