Skip to content
This repository was archived by the owner on Mar 27, 2023. It is now read-only.

Commit dd40bfc

Browse files
committed
wip update dependencies and local dev environment
1 parent ddecc9c commit dd40bfc

File tree

16 files changed

+114
-136
lines changed

16 files changed

+114
-136
lines changed

backend/.dockerignore

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
data/*
2+
static/*
3+
backup.json
4+
media/*
5+
notebooks/*
6+
.pytest_cache/

backend/apps/banking/tasks.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,17 @@
33
from io import StringIO
44

55
import celery
6-
from celery.task import task
76

87
from apps.banking.models import StatementFile, Transaction
98

9+
from backend.celery_app import app
10+
1011

1112
class BaseTask(celery.Task):
1213
pass
1314

1415

15-
@task(bind=True, base=BaseTask)
16+
@app.task(bind=True, base=BaseTask)
1617
def process_statement_file(self, statement_file_id):
1718

1819
"""

backend/apps/core/management/commands/watch_celery.py

Lines changed: 0 additions & 37 deletions
This file was deleted.

backend/apps/core/management/commands/watch_celery_beat.py

Lines changed: 0 additions & 33 deletions
This file was deleted.

backend/apps/core/management/commands/watch_daphne.py

Lines changed: 0 additions & 26 deletions
This file was deleted.

backend/apps/core/routing.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
from . import consumers
44

55
websocket_urlpatterns = [
6-
url(r"^ws/ping-pong/$", consumers.CoreConsumer),
7-
# url(r'^ws/chat/(?P<room_name>[^/]+)/$', consumers.CoreConsumer),
6+
url(
7+
r"^ws/ping-pong/$",
8+
consumers.CoreConsumer.as_asgi(),
9+
),
810
]

backend/apps/core/tasks.py

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,31 +2,27 @@
22

33
import celery
44
from celery.decorators import periodic_task
5-
from celery.task import task
6-
from celery.task.schedules import crontab
75
from django.core.mail import send_mail
86

7+
from backend.celery_app import app
8+
99

1010
# http://docs.celeryproject.org/en/latest/userguide/tasks.html#task-inheritance
1111
class BaseTask(celery.Task):
1212
pass
1313

1414

15-
@task(bind=True, base=BaseTask)
15+
@app.task(bind=True, base=BaseTask)
1616
def debug_task(self):
1717
time.sleep(10)
1818

1919

20-
@periodic_task(
21-
run_every=(crontab(minute="*/1")),
22-
name="debug_periodic_task",
23-
ignore_result=True,
24-
)
20+
@app.task(bind=True, base=BaseTask)
2521
def debug_periodic_task():
2622
print("Periodic task complete")
2723

2824

29-
@task(bind=True, base=BaseTask)
25+
@app.task(bind=True, base=BaseTask)
3026
def send_test_email_task(self):
3127
send_mail(
3228
"Email subject",
@@ -37,7 +33,7 @@ def send_test_email_task(self):
3733
)
3834

3935

40-
@task(bind=True, base=BaseTask)
36+
@app.task(bind=True, base=BaseTask)
4137
def sleep_task(self, seconds):
4238
time.sleep(int(seconds))
4339
return f"Slept {seconds} seconds"

backend/backend/routing.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
from channels.auth import AuthMiddlewareStack
22
from channels.routing import ProtocolTypeRouter, URLRouter
3+
from django.core.asgi import get_asgi_application
34

45
import apps.core.routing
56

67
application = ProtocolTypeRouter(
78
{
89
# Empty for now (http->django views is added by default)
10+
"http": get_asgi_application(),
911
"websocket": AuthMiddlewareStack(
1012
URLRouter(apps.core.routing.websocket_urlpatterns)
1113
),

backend/backend/settings/base.py

Lines changed: 40 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212

1313
import os
1414

15-
from kombu import Queue
15+
from kombu import Exchange, Queue
1616
import redis
1717

1818
# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
@@ -169,6 +169,15 @@
169169

170170
# Channels
171171

172+
CACHES = {
173+
"default": {
174+
"BACKEND": "django_redis.cache.RedisCache",
175+
"LOCATION": f"redis://{REDIS_SERVICE_HOST}:6379/4",
176+
"OPTIONS": {"CLIENT_CLASS": "django_redis.client.DefaultClient"},
177+
"KEY_PREFIX": "djangoredis",
178+
}
179+
}
180+
172181
CHANNEL_LAYERS = {
173182
"default": {
174183
"BACKEND": "channels_redis.core.RedisChannelLayer",
@@ -200,16 +209,44 @@
200209
}
201210

202211
# Celery Configuration
212+
CELERY_QUEUE_DEFAULT = "default"
213+
CELERY_QUEUE_OTHER = "other"
214+
215+
CELERY_BROKER_URL = f"redis://{REDIS_SERVICE_HOST}:6379/1" # noqa
216+
CELERY_RESULT_BACKEND = f"redis://{REDIS_SERVICE_HOST}:6379/2" # noqa
203217
CELERY_ACCEPT_CONTENT = ["application/json"]
204218
CELERY_TASK_SERIALIZER = "json"
205219
CELERY_RESULT_SERIALIZER = "json"
206-
CELERY_BROKER_URL = f"redis://{REDIS_SERVICE_HOST}:6379/1" # noqa
207-
CELERY_RESULT_BACKEND = f"redis://{REDIS_SERVICE_HOST}:6379/2" # noqa
208220

209221
CELERY_QUEUE_DEFAULT = 'default'
210222

211223
CELERY_QUEUES = (Queue(CELERY_QUEUE_DEFAULT, routing_key='default'),)
212224

225+
CELERY_QUEUES = (
226+
Queue(
227+
CELERY_QUEUE_DEFAULT,
228+
Exchange(CELERY_QUEUE_DEFAULT),
229+
routing_key=CELERY_QUEUE_DEFAULT,
230+
),
231+
Queue(
232+
CELERY_QUEUE_OTHER,
233+
Exchange(CELERY_QUEUE_OTHER),
234+
routing_key=CELERY_QUEUE_OTHER,
235+
),
236+
)
237+
238+
CELERY_DEFAULT_EXCHANGE_TYPE = "direct"
239+
CELERY_TASK_DEFAULT_QUEUE = CELERY_QUEUE_DEFAULT
240+
CELERY_TASK_DEFAULT_EXCHANGE = CELERY_QUEUE_DEFAULT
241+
CELERY_TASK_DEFAULT_ROUTING_KEY = CELERY_QUEUE_DEFAULT
242+
243+
CELERY_BEAT_SCHEDULE = {
244+
'debug-periodic': {
245+
'task': 'apps.core.tasks.debug_periodic_task',
246+
'schedule': 30, # scrape suppliers once every 5 minutes
247+
},
248+
}
249+
213250

214251
AUTH_USER_MODEL = "accounts.CustomUser"
215252

backend/requirements/base.txt

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
boto3==1.16.4
1+
boto3==1.16.23
22

3-
celery==4.4.7
4-
kombu==4.6.11
3+
celery==5.0.2
4+
kombu==5.0.2
55

6-
channels==2.4.0
7-
channels-redis==3.1.0
6+
channels==3.0.2
7+
channels-redis==3.2.0
88

9-
daphne==2.5.0
9+
daphne==3.0.1
1010

1111
graphene-django==2.13.0
1212
django-graphql-jwt==0.3.1

0 commit comments

Comments
 (0)