forked from DefectDojo/django-DefectDojo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
celery.py
42 lines (27 loc) · 1.04 KB
/
celery.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
import logging
import os
from celery import Celery
from celery.signals import setup_logging
from django.conf import settings
logger = logging.getLogger(__name__)
# set the default Django settings module for the 'celery' program.
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'dojo.settings.settings')
app = Celery('dojo')
# Using a string here means the worker will not have to
# pickle the object when using Windows.
app.config_from_object('django.conf:settings', namespace='CELERY')
app.autodiscover_tasks(lambda: settings.INSTALLED_APPS)
@app.task(bind=True)
def debug_task(self):
print(f'Request: {self.request!r}')
@setup_logging.connect
def config_loggers(*args, **kwags):
from logging.config import dictConfig
dictConfig(settings.LOGGING)
# from celery import current_app
# _ = current_app.loader.import_default_modules()
# tasks = list(sorted(name for name in current_app.tasks
# if not name.startswith('celery.')))
# logger.debug('registered celery tasks:')
# for task in tasks:
# logger.debug(task)