Advertisement
Guest User

Celery 'replace'

a guest
Sep 10th, 2015
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.77 KB | None | 0 0
  1. # test.py
  2. from celery import Celery, chord
  3. from celery.utils.log import get_task_logger
  4.  
  5. app = Celery('test', backend='redis://localhost:45000/10?new_join=1', broker='redis://localhost:45000/11')
  6. app.conf.CELERY_ALWAYS_EAGER = False
  7.  
  8. logger = get_task_logger(__name__)
  9.  
  10.  
  11. @app.task(bind=True)
  12. def get_one(self):
  13.     print('hello world')
  14.     self.replace(get_two.s())
  15.     return 1
  16.  
  17.  
  18. @app.task
  19. def get_two():
  20.     print('Returning two')
  21.     return 2
  22.  
  23.  
  24. @app.task
  25. def sum_all(data):
  26.     print('Logging data')
  27.     logger.error(data)
  28.     return sum(data)
  29.  
  30.  
  31. if __name__ == '__main__':
  32.     print('Running test')
  33.     x = chord(get_one.s() for i in range(3))
  34.     body = sum_all.s()
  35.     result = x(body)
  36.  
  37.     print(result.get())
  38.     print('Finished w/ test')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement