Skip to content

Commit

Permalink
fix: Counting of chord-chain tails of zero tasks
Browse files Browse the repository at this point in the history
  • Loading branch information
maybe-sybr committed Apr 27, 2021
1 parent b9b5ae9 commit 6c7a2c9
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions celery/canvas.py
Original file line number Diff line number Diff line change
Expand Up @@ -1424,8 +1424,15 @@ def _descend(cls, sig_obj):
subtasks = getattr(sig_obj.tasks, "tasks", sig_obj.tasks)
return sum(cls._descend(task) for task in subtasks)
elif isinstance(sig_obj, _chain):
# The last element in a chain counts toward this chord
return cls._descend(sig_obj.tasks[-1])
# The last non-empty element in a chain counts toward this chord
for child_sig in sig_obj.tasks[-1::-1]:
child_size = cls._descend(child_sig)
if child_size > 0:
return child_size
else:
# We have to just hope this chain is part of some encapsulating
# signature which is valid and can fire the chord body
return 0
elif isinstance(sig_obj, chord):
# The child chord's body counts toward this chord
return cls._descend(sig_obj.body)
Expand Down

0 comments on commit 6c7a2c9

Please sign in to comment.