Browse Source

Canvas: chord | sig, must attach sig to chord body. Closes #3356

Ask Solem 8 năm trước cách đây
mục cha
commit
6e147b3aba
1 tập tin đã thay đổi với 12 bổ sung1 xóa
  1. 12 1
      celery/canvas.py

+ 12 - 1
celery/canvas.py

@@ -424,18 +424,29 @@ class Signature(dict):
     def __or__(self, other):
         if isinstance(self, group):
             if isinstance(other, group):
+                # group() | group() -> single group
                 return group(_chain(self.tasks, other.tasks), app=self.app)
+            # group() | task -> chord
             return chord(self, body=other, app=self._app)
         elif isinstance(other, group):
+            # task | group() -> unroll group with one member
             other = maybe_unroll_group(other)
-
+            return chain(self, other, app=self._app)
         if not isinstance(self, chain) and isinstance(other, chain):
+            # task | chain -> chain
             return chain((self,) + other.tasks, app=self._app)
         elif isinstance(other, chain):
+            # chain | chain -> chain
             return chain(*self.tasks + other.tasks, app=self._app)
+        elif isinstance(self, chord):
+            sig = self.clone()
+            sig.body = sig.body | other
+            return sig
         elif isinstance(other, Signature):
             if isinstance(self, chain):
+                # chain | task -> chain
                 return chain(*self.tasks + (other,), app=self._app)
+            # task | task -> chain
             return chain(self, other, app=self._app)
         return NotImplemented