Browse Source

Task.si(*a, **k) is now .subtask(a, k, immutable=True)

Ask Solem 13 years ago
parent
commit
bb9c089a7a
2 changed files with 19 additions and 6 deletions
  1. 14 5
      celery/app/task.py
  2. 5 1
      docs/getting-started/next-steps.rst

+ 14 - 5
celery/app/task.py

@@ -736,24 +736,34 @@ class BaseTask(object):
         """``.s(*a, **k) -> .subtask(a, k)``"""
         return self.subtask(args, kwargs)
 
+    def si(self, *args, **kwargs):
+        """``.si(*a, **k) -> .subtask(a, k, immutable=True)``"""
+        return self.subtask(args, kwargs, immutable=True)
+
     def chunks(self, it, n):
+        """Creates a :class:`~celery.canvas.chunks` task for this task."""
         from celery import chunks
         return chunks(self.s(), it, n)
 
     def map(self, it):
+        """Creates a :class:`~celery.canvas.xmap` task from ``it``."""
         from celery import xmap
         return xmap(self.s(), it)
 
     def starmap(self, it):
+        """Creates a :class:`~celery.canvas.xstarmap` task from ``it``."""
         from celery import xstarmap
         return xstarmap(self.s(), it)
 
     def update_state(self, task_id=None, state=None, meta=None):
         """Update task state.
 
-        :param task_id: Id of the task to update.
-        :param state: New state (:class:`str`).
-        :param meta: State metadata (:class:`dict`).
+        :keyword task_id: Id of the task to update, defaults to the
+                          id of the current task
+        :keyword state: New state (:class:`str`).
+        :keyword meta: State metadata (:class:`dict`).
+
+
 
         """
         if task_id is None:
@@ -817,8 +827,7 @@ class BaseTask(object):
 
     def send_error_email(self, context, exc, **kwargs):
         if self.send_error_emails and not self.disable_error_emails:
-            sender = self.ErrorMail(self, **kwargs)
-            sender.send(context, exc)
+            self.ErrorMail(self, **kwargs).send(context, exc)
 
     def on_success(self, retval, task_id, args, kwargs):
         """Success handler.

+ 5 - 1
docs/getting-started/next-steps.rst

@@ -161,7 +161,11 @@ Sometimes you want to specify a callback that does not take
 additional arguments, and in that case you can set the subtask
 to be immutable::
 
-    >>> add.s(2, 2).link( reset_buffers.subtask(immutable=True) )
+    >>> add.apply_async((2, 2), link=reset_buffers.subtask(immutable=True))
+
+The ``.si()`` shortcut can also be used to create immutable subtasks::
+
+    >>> add.apply_async((2, 2), link=reset_buffers.si())
 
 Only the execution options can be set when a subtask is immutable,
 and it's not possible to apply the subtask with partial args/kwargs.