myapp.py 817 B

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