I’m using autodiscover in my celery.py file for gathering tasks. Which up until a recently picked all of the app.tasks.py up, I’m not sure why but my config.tasks.py function are no longer being picked up, but all the other apps are. If I from “config.tasks import *” there are no errors and I can run the tasks manually through shell.
ive tried using force=True on autodiscover which had no effect, and a number of other solutions, none of which seem to have any effect, does anyone have any ideas on what to check next?
Thanks
Structure:
JavaScript
x
15
15
1
-config
2
--apps.py
3
--views.py
4
--models.py
5
--tasks.py
6
-monitoring
7
--apps.py
8
--views.py
9
--models.py
10
--tasks.py
11
-app
12
--apps.py
13
--settings.py
14
--celery.py
15
celery config
JavaScript
1
17
17
1
from __future__ import absolute_import, unicode_literals
2
import os, django
3
from celery import Celery
4
5
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'app.settings')
6
7
django.setup() # This is key
8
9
app = Celery("app")
10
app.config_from_object('django.conf:settings', namespace='CELERY')
11
12
# Load task modules from all registered Django app configs.
13
app.autodiscover_tasks()
14
15
if __name__ == '__main__':
16
app.start()
17
settings.py
JavaScript
1
29
29
1
CELERY_TIMEZONE = 'Europe/London'
2
ENABLE_UTC = True
3
CELERY_BROKER_URL = 'redis://redis:6379'
4
CELERY_RESULT_BACKEND = 'redis://redis:6379'
5
CELERY_BEAT_SCHEDULER = 'django_celery_beat.schedulers:DatabaseScheduler'
6
CELERY_TASK_TIME_LIMIT = 540
7
8
INSTALLED_APPS = (
9
'django.contrib.admin',
10
'django.contrib.auth',
11
'django.contrib.contenttypes',
12
'django.contrib.sessions',
13
'django.contrib.messages',
14
'django.contrib.staticfiles',
15
'django.contrib.humanize',
16
'haystack',
17
'django_tables2',
18
'django_filters',
19
'django_celery_beat',
20
'config.apps.ConfigConfig',
21
'monitoring.apps.MonitoringConfig',
22
'storages',
23
'stdimage',
24
'simple_history',
25
'crispy_forms',
26
'rest_framework',
27
'rest_framework.authtoken',
28
)
29
tasks.py
JavaScript
1
13
13
1
from __future__ import absolute_import, unicode_literals
2
import requests, re, json, ipaddress, time, meraki, logging, random, gzip, diffios
3
from celery import chord, group
4
from app.celery import app
5
from django.conf import settings
6
from config.models import *
7
8
9
@app.task
10
def execute_command(device_id, cmd, user_id):
11
12
return output
13
console output
JavaScript
1
30
30
1
celery_1 | -------------- celery@3504f0d9bb2e v4.3.1 (rhubarb)
2
celery_1 | ---- **** -----
3
celery_1 | --- * *** * -- Linux-4.19.121-linuxkit-x86_64-with-debian-9.7 2021-02-09 12:14:41
4
celery_1 | -- * - **** ---
5
celery_1 | - ** ---------- [config]
6
celery_1 | - ** ---------- .> app: app:0x7f82527f04a8
7
celery_1 | - ** ---------- .> transport: redis://redis:6379//
8
celery_1 | - ** ---------- .> results: redis://redis:6379/
9
celery_1 | - *** --- * --- .> concurrency: 30 (prefork)
10
celery_1 | -- ******* ---- .> task events: OFF (enable -E to monitor tasks in this worker)
11
celery_1 | --- ***** -----
12
celery_1 | -------------- [queues]
13
celery_1 | .> celery exchange=celery(direct) key=celery
14
celery_1 |
15
celery_1 |
16
celery_1 | [tasks]
17
celery_1 | . app_settings.tasks.import_meraki_templates
18
celery_1 | . celery.accumulate
19
celery_1 | . celery.backend_cleanup
20
celery_1 | . celery.chain
21
celery_1 | . celery.chord
22
celery_1 | . celery.chord_unlock
23
celery_1 | . celery.chunks
24
celery_1 | . celery.group
25
celery_1 | . celery.map
26
celery_1 | . celery.starmap
27
celery_1 | . app.celery.debug_task
28
celery_1 | . monitoring.tasks.link_checks
29
celery_1 | . monitoring.tasks.service_checks
30
Advertisement
Answer
I rebuilt my docker container and now they’re all loading again, not sure what would of caused this but its working!