Advertisement
Guest User

Untitled

a guest
Aug 19th, 2019
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.36 KB | None | 0 0
  1. import random
  2.  
  3. from celery import Celery
  4.  
  5. app = Celery('add', broker='redis://localhost:6379/0')
  6.  
  7. @app.task(bind=True)
  8. def add(self, x, y):
  9. # Get a random number between 1 and 10
  10. num = random.randint(1, 10)
  11. print num # To help properly understand output
  12. try:
  13. # If number is odd, fail the task
  14. if num % 2:
  15. raise Exception()
  16. # If number is even, succeed the task
  17. else:
  18. return x + y
  19. except Exception as e:
  20. self.retry(countdown=2, exc=e, max_retries=1)
  21.  
  22. [2015-07-31 17:47:33,681: INFO/MainProcess] Received task: add.add[64e43f81-0f80-49ac-a068-4c84c689ea16]
  23. [2015-07-31 17:47:33,681: WARNING/Worker-2] 7
  24. [2015-07-31 17:47:33,703: INFO/MainProcess] Received task: add.add[64e43f81-0f80-49ac-a068-4c84c689ea16] eta:[2015-07-31 12:17:35.692557+00:00]
  25. [2015-07-31 17:47:33,704: INFO/MainProcess] Task add.add[64e43f81-0f80-49ac-a068-4c84c689ea16] retry: Retry in 2s: Exception()
  26. [2015-07-31 17:47:36,890: WARNING/Worker-4] 3
  27. [2015-07-31 17:47:36,894: ERROR/MainProcess] Task add.add[64e43f81-0f80-49ac-a068-4c84c689ea16] raised unexpected: Exception()
  28. Traceback (most recent call last):
  29. File "/Users/akshar/.virtualenvs/hack/lib/python2.7/site-packages/celery/app/trace.py", line 240, in trace_task
  30. ...
  31. File "/Users/akshar/Play/Python/hack/add.py", line 15, in add
  32. raise Exception()
  33. Exception
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement