myapp.py 759 B

12345678910111213141516171819202122232425262728293031323334353637383940
  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(
  18. 'myapp',
  19. broker='amqp://guest@localhost//',
  20. # ## add result backend here if needed.
  21. # backend='rpc'
  22. )
  23. @app.task
  24. def add(x, y):
  25. return x + y
  26. if __name__ == '__main__':
  27. app.start()