|
@@ -23,6 +23,8 @@ from celery.worker import state
|
|
|
|
|
|
|
|
|
EMAIL_SIGNATURE_SEP = "-- "
|
|
|
+
|
|
|
+
|
|
|
TASK_ERROR_EMAIL_BODY = """
|
|
|
Task %%(name)s with id %%(id)s raised exception:\n%%(exc)s
|
|
|
|
|
@@ -39,16 +41,20 @@ celeryd at %%(hostname)s.
|
|
|
""" % {"EMAIL_SIGNATURE_SEP": EMAIL_SIGNATURE_SEP}
|
|
|
|
|
|
|
|
|
+
|
|
|
+
|
|
|
WANTED_DELIVERY_INFO = ("exchange", "routing_key", "consumer_tag", )
|
|
|
|
|
|
|
|
|
class InvalidTaskError(Exception):
|
|
|
"""The task has invalid data or is not properly constructed."""
|
|
|
+ pass
|
|
|
|
|
|
|
|
|
class AlreadyExecutedError(Exception):
|
|
|
"""Tasks can only be executed once, as they might change
|
|
|
world-wide state."""
|
|
|
+ pass
|
|
|
|
|
|
|
|
|
class WorkerTaskTrace(TaskTrace):
|
|
@@ -76,6 +82,12 @@ class WorkerTaskTrace(TaskTrace):
|
|
|
|
|
|
"""
|
|
|
|
|
|
+
|
|
|
+ loader = None
|
|
|
+
|
|
|
+
|
|
|
+ hostname = None
|
|
|
+
|
|
|
def __init__(self, *args, **kwargs):
|
|
|
self.loader = kwargs.get("loader") or app_or_default().loader
|
|
|
self.hostname = kwargs.get("hostname") or socket.gethostname()
|
|
@@ -152,71 +164,70 @@ def execute_and_trace(task_name, *args, **kwargs):
|
|
|
|
|
|
|
|
|
class TaskRequest(object):
|
|
|
- """A request for task execution.
|
|
|
-
|
|
|
- :param task_name: see :attr:`task_name`.
|
|
|
- :param task_id: see :attr:`task_id`.
|
|
|
- :param args: see :attr:`args`
|
|
|
- :param kwargs: see :attr:`kwargs`.
|
|
|
-
|
|
|
- .. attribute:: task_name
|
|
|
-
|
|
|
- Kind of task. Must be a name registered in the task registry.
|
|
|
-
|
|
|
- .. attribute:: task_id
|
|
|
-
|
|
|
- UUID of the task.
|
|
|
+ """A request for task execution."""
|
|
|
|
|
|
- .. attribute:: args
|
|
|
+
|
|
|
+ name = None
|
|
|
|
|
|
- List of positional arguments to apply to the task.
|
|
|
+
|
|
|
+ task = None
|
|
|
|
|
|
- .. attribute:: kwargs
|
|
|
+
|
|
|
+ task_id = None
|
|
|
|
|
|
- Mapping of keyword arguments to apply to the task.
|
|
|
+
|
|
|
+ args = None
|
|
|
|
|
|
- .. attribute:: on_ack
|
|
|
+
|
|
|
+ kwargs = None
|
|
|
|
|
|
- Callback called when the task should be acknowledged.
|
|
|
+
|
|
|
+ retries = 0
|
|
|
|
|
|
- .. attribute:: message
|
|
|
+
|
|
|
+ eta = None
|
|
|
|
|
|
- The original message sent. Used for acknowledging the message.
|
|
|
+
|
|
|
+ expires = None
|
|
|
|
|
|
- .. attribute:: executed
|
|
|
+
|
|
|
+ on_ack = None
|
|
|
|
|
|
- Set to :const:`True` if the task has been executed.
|
|
|
- A task should only be executed once.
|
|
|
+
|
|
|
+ message = None
|
|
|
|
|
|
- .. attribute:: delivery_info
|
|
|
-
|
|
|
- Additional delivery info, e.g. the contains the path
|
|
|
- from producer to consumer.
|
|
|
+
|
|
|
+ executed = False
|
|
|
|
|
|
- .. attribute:: acknowledged
|
|
|
+
|
|
|
+
|
|
|
+ delivery_info = None
|
|
|
|
|
|
- Set to :const:`True` if the task has been acknowledged.
|
|
|
+
|
|
|
+ acknowledged = False
|
|
|
|
|
|
- """
|
|
|
-
|
|
|
+
|
|
|
success_msg = "Task %(name)s[%(id)s] processed: %(return_value)s"
|
|
|
- error_msg = """
|
|
|
+
|
|
|
+
|
|
|
+ error_msg = """\
|
|
|
Task %(name)s[%(id)s] raised exception: %(exc)s\n%(traceback)s
|
|
|
"""
|
|
|
- retry_msg = """
|
|
|
- Task %(name)s[%(id)s] retry: %(exc)s
|
|
|
- """
|
|
|
|
|
|
-
|
|
|
- email_subject = """
|
|
|
+
|
|
|
+ retry_msg = """Task %(name)s[%(id)s] retry: %(exc)s"""
|
|
|
+
|
|
|
+
|
|
|
+ email_subject = """\
|
|
|
[celery@%(hostname)s] Error: Task %(name)s (%(id)s): %(exc)s
|
|
|
"""
|
|
|
+
|
|
|
+
|
|
|
email_body = TASK_ERROR_EMAIL_BODY
|
|
|
|
|
|
-
|
|
|
- executed = False
|
|
|
- acknowledged = False
|
|
|
+
|
|
|
time_start = None
|
|
|
+
|
|
|
_already_revoked = False
|
|
|
|
|
|
def __init__(self, task_name, task_id, args, kwargs,
|
|
@@ -513,12 +524,6 @@ class TaskRequest(object):
|
|
|
body = self.email_body.strip() % context
|
|
|
self.app.mail_admins(subject, body, fail_silently=fail_silently)
|
|
|
|
|
|
- def __repr__(self):
|
|
|
- return '<%s: {name:"%s", id:"%s", args:"%s", kwargs:"%s"}>' % (
|
|
|
- self.__class__.__name__,
|
|
|
- self.task_name, self.task_id,
|
|
|
- self.args, self.kwargs)
|
|
|
-
|
|
|
def info(self, safe=False):
|
|
|
args = self.args
|
|
|
kwargs = self.kwargs
|
|
@@ -541,3 +546,10 @@ class TaskRequest(object):
|
|
|
self.task_id,
|
|
|
self.eta and " eta:[%s]" % (self.eta, ) or "",
|
|
|
self.expires and " expires:[%s]" % (self.expires, ) or "")
|
|
|
+
|
|
|
+ def __repr__(self):
|
|
|
+ return '<%s: {name:"%s", id:"%s", args:"%s", kwargs:"%s"}>' % (
|
|
|
+ self.__class__.__name__,
|
|
|
+ self.task_name, self.task_id,
|
|
|
+ self.args, self.kwargs)
|
|
|
+
|