Created
March 6, 2018 19:37
-
-
Save npilon/060683a02c4b96fb79316786fcc22f51 to your computer and use it in GitHub Desktop.
Demonstrate inconsistent behavior of celery.canvas.chord in celery 4.1.0
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
"""Demonstrate inconsistent chord header result values: | |
Run by:: | |
pip install celery redis | |
python minimal_chord_chain.py worker --loglevel INFO --config=minimal_chord_chain | |
# Separate shell | |
python minimal_chord_chain.py shell --config=minimal_chord_chain | |
from minimal_chord_chain import test; test() | |
Results are inspectable in logging in worker's shell. Note that sometimes | |
``vs`` is a scalar (an int, in this case) and sometimes it's a list. This seems | |
like it does not match the documented behavior of ``chord``: | |
> The body is applied with the return values of all the header tasks as a list. | |
""" | |
import celery | |
from celery.canvas import chord, group | |
app = celery.Celery() | |
CELERY_RESULT_BACKEND = "redis://localhost/0" | |
@app.task() | |
def starter(v): | |
return v | |
@app.task() | |
def stepper(v): | |
return v + 1 | |
@app.task() | |
def resulter(vs, test): | |
return vs, repr(type(vs)), test | |
def test(): | |
chord([ | |
starter.s(1) | | |
stepper.s(), | |
])(resulter.s('single task, scalar result')) | |
chord([ | |
starter.s(1) | | |
stepper.s(), | |
starter.s(11) | | |
stepper.s(), | |
])(resulter.s('multiple tasks, list result')) | |
def main(): | |
app.start() | |
if __name__ == '__main__': | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment