celery.py 711 B

12345678910111213141516171819202122
  1. from __future__ import absolute_import, unicode_literals
  2. import os
  3. from celery import Celery
  4. # set the default Django settings module for the 'celery' program.
  5. os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'proj.settings')
  6. app = Celery('proj')
  7. # Using a string here means the worker doesn't have to serialize
  8. # the configuration object to child processes.
  9. # - namespace='CELERY' means all celery-related configuration keys
  10. # should have a `CELERY_` prefix.
  11. app.config_from_object('django.conf:settings', namespace='CELERY')
  12. # Load task modules from all registered Django app configs.
  13. app.autodiscover_tasks()
  14. @app.task(bind=True)
  15. def debug_task(self):
  16. print('Request: {0!r}'.format(self.request))