def test_grouping(): result = group(add.s(i, i) for i in range(10, 20))().get() print(result) result = chain(add.s(2, 2) | mul.s((4)))().get() print(result) result = chord((mul.s(i, i) for i in range(10)), xsum.s())().get() print(result) result = (group(mul.s(i, i) for i in range(10)) | xsum.s())().get() print(result)
def test_group_results(): job = group([ add.s(2, 4), mul.s(4, 9), xsum.s([2, 3, 5]), ]) result = job.apply_async() print(result.ready()) print(result.successful()) print(result.join()) print(result.get())
print('Chain result: %s' % res.get()) # shortcut of above res = (add.s(2, 2) | add.s(4) | add.s(8))() print('Chain shortcut: %s' % res.get()) res = chain(add.si(2, 2), add.si(4, 5), add.si(8, 8))() print('Chain with independent task: %s' % res.get()) # 8 + 8 print('Parent result: %s' % res.parent.get()) # 4 + 5 print('Parent of parent result: %s' % res.parent.parent.get()) # 2 + 2 ## group primitive res = group(add.s(i, i) for i in range(10))() print('Group result: %s' % res.get()) ## chord primitive res = chord((add.s(i, i) for i in range(10)), xsum.s())() # is equal to: group(add.s(i, i) for i in range(10)) | xsum.s() print('Chord result: %s' % res.get()) res = chord([add.s(2, 2), raise_error.s(), add.s(4, 4)], xsum.s())() print(res.get(propagate=False)) print('Map result: %s' % ~xsum.map([list(range(10)), list(range(100))])) print('Starmap result: %s' % ~add.starmap(zip(range(10), range(10)))) print('Chunks result: %s' % ~add.chunks(zip(range(100), range(100)), 10))
# group( # (add.s(4, 4) | mul.s(2)), # 16 # (add.s(5, 4) | mul.s(3)), # 27 # (add.s(5, 5) | mul.s(4)) # 40 # ) # | xsum.s() # 83 # ) # res.apply_async() # raise exception still can run, and call handle error function res = ( group( (add.s(4, 4) | mul.s(2)), # 16 (add.s(5, 4) | mul.s(3)), # 27 (add.s(5, 5) | mul.s(4)) # 40 ) | xsum.s() # 83 ) res.apply_async(link_error=report_error()) # raise exception then it's run forever # res = ( # group( # (add.s(4, 4) | mul.s(2)), # 16 # (add.s(5, 4) | mul.s(3)), # 27 # (add.s(5, 5) | mul.s(4)) # 40 # ) # | xsum.s() # 83 # ) # res().get()
from tasks import add, append, xsum from celery import chord, group print("HERE") res = chord((add.s(i, i) for i in range(10)), xsum.s())() print(res.get()) res = group(add.s(i, i) for i in range(10))() print(res.get()) res = chord(add.s(x, x) for x in range(7))(append.si('complete and '), interval=1) print(res.get())
def test_complex_chord(): result = chord(mul.s(i, i) for i in range(100))(xsum.s()).get() print(result)