I’m have a project split on 2 separate apps and both have another shared app as reusable one(i store my models there and install it from git link. So when i run celery worker locally all is working perfect, but if i use docker(with celery in separate image) i got this error
JavaScript
x
4
1
Error:
2
celery_api | Unable to load celery application.
3
celery_api | The module common was not found.
4
In some reason celery gets improper configuration from django.
celery docker config
JavaScript
1
14
14
1
celery_api:
2
image: celery_api
3
container_name: celery_api
4
restart: unless-stopped
5
build: .
6
command: celery worker -A djookyapi --loglevel=info
7
env_file:
8
- ./.dev.env
9
volumes:
10
- .:/usr/src/app
11
working_dir: /usr/src/app
12
networks:
13
- dev
14
celery file in the root of project folder(near settings.py file)
JavaScript
1
35
35
1
__future__ import absolute_import, unicode_literals
2
3
import os
4
import sys
5
6
from celery import Celery
7
from django.conf import settings
8
9
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
10
sys.path.append(BASE_DIR)
11
# set the default Django settings module for the 'celery' program.
12
13
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'myproj.settings')
14
os.environ.setdefault('DJANGO_CONFIGURATION', 'Local')
15
16
import configurations
17
18
configurations.setup()
19
20
app = Celery('myproj', )
21
22
# Using a string here means the worker doesn't have to serialize
23
# the configuration object to child processes.
24
# - namespace='CELERY' means all celery-related configuration keys
25
# should have a `CELERY_` prefix.
26
app.config_from_object('django.conf:settings')
27
28
# Load task modules from all registered Django app configs.
29
app.autodiscover_tasks(lambda: settings.INSTALLED_APPS)
30
31
32
@app.task(bind=True)
33
def debug_task(self):
34
print('Request: {0!r}'.format(self.request))
35
So why celery doesn’t see my app?
Advertisement
Answer
changed config in docker-compose like this:
JavaScript
1
13
13
1
celery_api:
2
image: celery_api:latest
3
container_name: celery_api
4
restart: unless-stopped
5
build:
6
context: ./
7
command: celery worker -A djookyapi --loglevel=info -B
8
env_file:
9
- ./.dev.env
10
working_dir: /usr/src/app
11
networks:
12
- dev
13