celery.py 634 B

123456789101112131415161718192021222324
  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. from django.conf import settings # noqa
  7. app = Celery('proj')
  8. # Using a string here means the worker does not have to serialize
  9. # the configuration object.
  10. app.config_from_object('django.conf:settings', namespace='CELERY')
  11. # load task modules from all registered Django app configs.
  12. app.autodiscover_tasks()
  13. @app.task(bind=True)
  14. def debug_task(self):
  15. print('Request: {0!r}'.format(self.request))