myapp.py 777 B

123456789101112131415161718192021222324252627282930313233343536
  1. """myapp.py
  2. Usage:
  3. (window1)$ python myapp.py worker -l info
  4. (window2)$ python
  5. >>> from myapp import add
  6. >>> add.delay(16, 16).get()
  7. 32
  8. You can also specify the app to use with the `celery` command,
  9. using the `-A` / `--app` option::
  10. $ celery -A myapp worker -l info
  11. With the `-A myproj` argument the program will search for an app
  12. instance in the module ``myproj``. You can also specify an explicit
  13. name using the fully qualified form::
  14. $ celery -A myapp:app worker -l info
  15. """
  16. from celery import Celery
  17. app = Celery('myapp', broker='amqp://guest@localhost//')
  18. # New When celery > 3.1, must specify result_backend
  19. app.conf.CELERY_RESULT_BACKEND = 'amqp'
  20. @app.task()
  21. def add(x, y):
  22. return x + y
  23. if __name__ == '__main__':
  24. app.start()