-
Notifications
You must be signed in to change notification settings - Fork 12
/
celery.py
30 lines (21 loc) · 941 Bytes
/
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
from __future__ import annotations
import os
from celery import Celery, signals
import celery.app.trace
import configurations.importer
celery.app.trace.LOG_RECEIVED = """\
Task %(name)s[%(id)s] received: (%(args)s, %(kwargs)s)\
"""
os.environ['DJANGO_SETTINGS_MODULE'] = 'dandiapi.settings'
if not os.environ.get('DJANGO_CONFIGURATION'):
raise ValueError('The environment variable "DJANGO_CONFIGURATION" must be set.')
configurations.importer.install()
# Using a string config_source means the worker doesn't have to serialize
# the configuration object to child processes.
app = Celery(config_source='django.conf:settings', namespace='CELERY')
# Load task modules from all registered Django app configs.
app.autodiscover_tasks()
@signals.import_modules.connect
def _register_scheduled_tasks(sender, **kwargs):
from dandiapi.api.tasks.scheduled import register_scheduled_tasks
register_scheduled_tasks(sender, **kwargs)