浏览代码

Canvas: signature() now properly forwards app argument

Ask Solem 10 年之前
父节点
当前提交
3432167e8b
共有 1 个文件被更改,包括 12 次插入9 次删除
  1. 12 9
      celery/canvas.py

+ 12 - 9
celery/canvas.py

@@ -181,7 +181,7 @@ class Signature(dict):
                 dict(self.kwargs, **kwargs) if kwargs else self.kwargs,
                 dict(self.options, **options) if options else self.options)
 
-    def clone(self, args=(), kwargs={}, **opts):
+    def clone(self, args=(), kwargs={}, app=None, **opts):
         # need to deepcopy options so origins links etc. is not modified.
         if args or kwargs or opts:
             args, kwargs, opts = self._merge(args, kwargs, opts)
@@ -190,7 +190,8 @@ class Signature(dict):
         s = Signature.from_dict({'task': self.task, 'args': tuple(args),
                                  'kwargs': kwargs, 'options': deepcopy(opts),
                                  'subtask_type': self.subtask_type,
-                                 'immutable': self.immutable}, app=self._app)
+                                 'immutable': self.immutable},
+                                app=app or self._app)
         s._type = self._type
         return s
     partial = clone
@@ -540,6 +541,10 @@ class group(Signature):
     def __repr__(self):
         return repr(self.tasks)
 
+    @property
+    def app(self):
+        return self._app or (self.tasks[0].app if self.tasks else current_app)
+
     @property
     def type(self):
         if self._type:
@@ -547,8 +552,7 @@ class group(Signature):
         # taking the app from the first task in the list, there may be a
         # better solution for this, e.g. to consolidate tasks with the same
         # app and apply them in batches.
-        app = self._app if self._app else self.tasks[0].type.app
-        return app.tasks[self['task']]
+        return self.app.tasks[self['task']]
 
 
 @Signature.register_type
@@ -641,12 +645,12 @@ class chord(Signature):
     body = _getitem_property('kwargs.body')
 
 
-def signature(varies, *args, **kwargs):
+def signature(varies, args=(), kwargs={}, options={}, app=None, **kw):
     if isinstance(varies, dict):
         if isinstance(varies, Signature):
-            return varies.clone()
-        return Signature.from_dict(varies)
-    return Signature(varies, *args, **kwargs)
+            return varies.clone(app=app)
+        return Signature.from_dict(varies, app=app)
+    return Signature(varies, args, kwargs, options, app=app, **kw)
 subtask = signature   # XXX compat
 
 
@@ -660,5 +664,4 @@ def maybe_signature(d, app=None):
         if app is not None:
             d._app = app
         return d
-
 maybe_subtask = maybe_signature  # XXX compat