Skip to content

Commit 00ae28f

Browse files
committed
dependencies: add celery and celery beat to the project
Signed-off-by: andrepapoti <[email protected]>
1 parent bb3aae5 commit 00ae28f

File tree

6 files changed

+85
-0
lines changed

6 files changed

+85
-0
lines changed

docker-compose.yml

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,3 +35,56 @@ services:
3535
- DATABASE_NAME=patchwork
3636
- DATABASE_USER=patchwork
3737
- DATABASE_PASSWORD=password
38+
39+
redis:
40+
image: redis:alpine
41+
ports:
42+
- 6379:6379
43+
44+
celery:
45+
build:
46+
context: .
47+
dockerfile: ./tools/docker/Dockerfile
48+
args:
49+
- UID
50+
- GID
51+
user: patchwork
52+
command: ["celery", "-A", "patchwork", "worker", "--loglevel=info"]
53+
volumes:
54+
- .:/home/patchwork/patchwork/
55+
depends_on:
56+
- db
57+
- redis
58+
environment:
59+
- UID
60+
- GID
61+
# skip DATABASE_TYPE explicitly as mysql should be the default type.
62+
- DATABASE_HOST=db
63+
- DATABASE_PORT=3306
64+
- DATABASE_NAME=patchwork
65+
- DATABASE_USER=patchwork
66+
- DATABASE_PASSWORD=password
67+
68+
celerybeat:
69+
build:
70+
context: .
71+
dockerfile: ./tools/docker/Dockerfile
72+
args:
73+
- UID
74+
- GID
75+
user: patchwork
76+
command: ["celery", "-A", "patchwork", "beat", "--loglevel=info", "--scheduler", "django_celery_beat.schedulers:DatabaseScheduler"]
77+
volumes:
78+
- .:/home/patchwork/patchwork/
79+
depends_on:
80+
- db
81+
- redis
82+
environment:
83+
- UID
84+
- GID
85+
# skip DATABASE_TYPE explicitly as mysql should be the default type.
86+
- DATABASE_HOST=db
87+
- DATABASE_PORT=3306
88+
- DATABASE_NAME=patchwork
89+
- DATABASE_USER=patchwork
90+
- DATABASE_PASSWORD=password

patchwork/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,11 @@
33
#
44
# SPDX-License-Identifier: GPL-2.0-or-later
55

6+
from patchwork.celery import app as celery_app
67
from patchwork.version import get_str_version
78
from patchwork.version import get_latest_version
89

910
VERSION = get_str_version()
1011

1112
__version__ = get_latest_version()
13+
__all__ = ('celery_app',)

patchwork/celery.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import os
2+
from celery import Celery
3+
4+
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'patchwork.settings')
5+
6+
app = Celery('patchwork')
7+
8+
app.config_from_object('django.conf:settings', namespace='CELERY')
9+
10+
app.autodiscover_tasks()

patchwork/settings/base.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,20 @@
187187
'NON_FIELD_ERRORS_KEY': 'detail',
188188
}
189189

190+
# Celery settings
191+
192+
INSTALLED_APPS += ['django_celery_beat']
193+
194+
CELERY_BROKER_URL = 'redis://redis:6379/0'
195+
CELERY_RESULT_BACKEND = 'redis://redis:6379/0'
196+
CELERY_ACCEPT_CONTENT = ['json']
197+
CELERY_TASK_SERIALIZER = 'json'
198+
CELERY_RESULT_SERIALIZER = 'json'
199+
CELERY_TIMEZONE = 'UTC'
200+
201+
CELERY_BEAT_SCHEDULER = 'django_celery_beat.schedulers:DatabaseScheduler'
202+
DJANGO_CELERY_BEAT_TZ_AWARE = False
203+
190204
#
191205
# Logging settings
192206
#

requirements-dev.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,7 @@ djangorestframework~=3.14.0
33
django-filter~=23.5.0
44
django-debug-toolbar~=4.2.0
55
django-dbbackup~=4.1.0
6+
celery~=5.3.0
7+
redis~=5.0.0
8+
django-celery-beat~=2.6.0
69
-r requirements-test.txt

requirements-prod.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,6 @@ djangorestframework~=3.14.0
33
django-filter~=23.5.0
44
psycopg2~=2.9.0
55
sqlparse~=0.4.0
6+
celery~=5.3.0
7+
redis~=5.0.0
8+
django-celery-beat~=2.6.0

0 commit comments

Comments
 (0)