Browse Source

Adds igroup & ichain as immutable shortcuts

Ask Solem 12 years ago
parent
commit
039a1e8faf
4 changed files with 26 additions and 14 deletions
  1. 6 6
      celery/__init__.py
  2. 4 2
      celery/bin/celery.py
  3. 6 4
      celery/canvas.py
  4. 10 2
      docs/reference/celery.rst

+ 6 - 6
celery/__init__.py

@@ -23,12 +23,12 @@ from .__compat__ import recreate_module
 
 old_module, new_module = recreate_module(__name__,  # pragma: no cover
     by_module={
-        'celery.app':          ['Celery', 'bugreport', 'shared_task'],
-        'celery.app.task':     ['Task'],
-        'celery._state':       ['current_app', 'current_task'],
-        'celery.canvas':       ['chain', 'chord', 'chunks',
-                                'group', 'subtask', 'xmap', 'xstarmap'],
-        'celery.utils':        ['uuid'],
+        'celery.app':      ['Celery', 'bugreport', 'shared_task'],
+        'celery.app.task': ['Task'],
+        'celery._state':   ['current_app', 'current_task'],
+        'celery.canvas':   ['chain', 'chord', 'ichord', 'chunks', 'group',
+                            'igroup', 'subtask', 'xmap', 'xstarmap'],
+        'celery.utils':    ['uuid'],
     },
     direct={'task': 'celery.task'},
     __package__='celery', __file__=__file__,

+ 4 - 2
celery/bin/celery.py

@@ -684,8 +684,8 @@ class shell(Command):  # pragma: no cover
     The following symbols will be added to the main globals:
 
         - celery:  the current application.
-        - chord, group, chain, chunks, xmap, xstarmap
-          subtask, Task
+        - chord, ichord, group, igroup, chain,
+          chunks, xmap, xstarmap subtask, Task
         - all registered tasks.
 
     Example Session::
@@ -729,7 +729,9 @@ class shell(Command):  # pragma: no cover
         self.locals = {'celery': self.app,
                        'Task': celery.Task,
                        'chord': celery.chord,
+                       'ichord': celery.ichord,
                        'group': celery.group,
+                       'igroup': celery.igroup,
                        'chain': celery.chain,
                        'chunks': celery.chunks,
                        'xmap': celery.xmap,

+ 6 - 4
celery/canvas.py

@@ -8,6 +8,7 @@
 """
 from __future__ import absolute_import
 
+from functools import partial
 from operator import itemgetter
 from itertools import chain as _chain
 
@@ -201,7 +202,7 @@ class chain(Signature):
 
     def __init__(self, *tasks, **options):
         tasks = tasks[0] if len(tasks) == 1 and is_list(tasks[0]) else tasks
-        Signature.__init__(self, 'celery.chain', (), {'tasks': tasks}, options)
+        Signature.__init__(self, 'celery.chain', (), {'tasks': tasks}, **options)
         self.tasks = tasks
         self.subtask_type = 'chain'
 
@@ -296,7 +297,7 @@ class group(Signature):
     def __init__(self, *tasks, **options):
         if len(tasks) == 1:
             tasks = _maybe_group(tasks[0])
-        Signature.__init__(self, 'celery.group', (), {'tasks': tasks}, options)
+        Signature.__init__(self, 'celery.group', (), {'tasks': tasks}, **options)
         self.tasks, self.subtask_type = tasks, 'group'
 
     @classmethod
@@ -320,6 +321,7 @@ class group(Signature):
     def __repr__(self):
         return repr(self.tasks)
 Signature.register_type(group)
+igroup = partial(group, immutable=True)
 
 
 class chord(Signature):
@@ -328,7 +330,7 @@ class chord(Signature):
     def __init__(self, header, body=None, **options):
         Signature.__init__(self, 'celery.chord', (),
                          {'header': _maybe_group(header),
-                          'body': maybe_subtask(body)}, options)
+                          'body': maybe_subtask(body)}, **options)
         self.subtask_type = 'chord'
 
     @classmethod
@@ -376,7 +378,7 @@ class chord(Signature):
     def body(self):
         return self.kwargs.get('body')
 Signature.register_type(chord)
-
+ichord = partial(chord, immutable=True)
 
 def subtask(varies, *args, **kwargs):
     if not (args or kwargs) and isinstance(varies, dict):

+ 10 - 2
docs/reference/celery.rst

@@ -247,7 +247,7 @@ Application
 Grouping Tasks
 --------------
 
-.. class:: group(tasks=[])
+.. class:: group(task1[, task2[, task3[,... taskN]]])
 
     Creates a group of tasks to be executed in parallel.
 
@@ -259,6 +259,10 @@ Grouping Tasks
 
     The ``apply_async`` method returns :class:`~@GroupResult`.
 
+.. class:: igroup(task1[, task2[, task3[,... taskN]]])
+
+    Immutable :class:`group` (i.e. will not modify arguments).
+
 .. class:: chain(task1[, task2[, task3[,... taskN]]])
 
     Chains tasks together, so that each tasks follows each other
@@ -282,7 +286,7 @@ Grouping Tasks
         >>> res.parent.get()
         4
 
-.. class:: chord(header)(body)
+.. class:: chord(header[, body])
 
     A chord consists of a header and a body.
     The header is a group of tasks that must complete before the callback is
@@ -300,6 +304,10 @@ Grouping Tasks
     The body is applied with the return values of all the header
     tasks as a list.
 
+.. class:: ichord(header[, body])
+
+    Immutable :class:`chord` (i.e. will not modify arguments).
+
 .. class:: subtask(task=None, args=(), kwargs={}, options={})
 
     Describes the arguments and execution options for a single task invocation.