myapp.py 774 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  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 celeryd::
  9. $ celeryd -l info --app=myapp.celery
  10. """
  11. from celery import Celery
  12. def debug_args(fun):
  13. from kombu.utils import reprcall
  14. def _inner(self, *args, **kwargs):
  15. print("CALL: %r" % reprcall(self.name, args, kwargs))
  16. return fun(*args, **kwargs)
  17. return _inner
  18. celery = Celery("myapp")
  19. celery.conf.update(
  20. BROKER_URL="amqp://guest:guest@localhost:5672//",
  21. CELERY_ANNOTATIONS={
  22. "myapp.add": {"@__call__": debug_args},
  23. },
  24. )
  25. @celery.task
  26. def add(x, y):
  27. return x + y
  28. if __name__ == "__main__":
  29. celery.start()