From ae8a048ea6a570e9a15ba67d954297582b4ddeca Mon Sep 17 00:00:00 2001 From: Jonas Winkler Date: Sat, 7 Nov 2020 12:47:17 +0100 Subject: [PATCH] fixed up the docker --- Pipfile | 1 + Pipfile.lock | 4 ++-- scripts/supervisord.conf | 4 ++-- src/paperless/asgi.py | 30 ++++++++---------------------- src/paperless/consumers.py | 16 ++++++++++++++++ src/paperless/settings.py | 2 +- src/paperless/urls.py | 8 +++++++- 7 files changed, 37 insertions(+), 28 deletions(-) create mode 100644 src/paperless/consumers.py diff --git a/Pipfile b/Pipfile index d526ae252..09de36334 100644 --- a/Pipfile +++ b/Pipfile @@ -28,6 +28,7 @@ django-extensions = "" watchdog = "*" channels = "~=3.0" channels-redis = "*" +daphne = "~=3.0" [dev-packages] coveralls = "*" diff --git a/Pipfile.lock b/Pipfile.lock index 642e38214..21b4becad 100644 --- a/Pipfile.lock +++ b/Pipfile.lock @@ -1,7 +1,7 @@ { "_meta": { "hash": { - "sha256": "192d7419b844e6bb81fed793e7766b2ba15f2a016af1a33fc73cf09e12de5fb7" + "sha256": "66530e76de7948d8123529eff0b150926aa46a410da8b31e12b6d468e5996e7a" }, "pipfile-spec": 6, "requires": {}, @@ -157,7 +157,7 @@ "sha256:60856f7efa0b1e1b969efa074e8698bd09de4713ecc06e6a4d19d04c66c4a3bd", "sha256:b43e70d74ff832a634ff6c92badd208824e4530e08b340116517e5aad0aca774" ], - "markers": "python_version >= '3.6'", + "index": "pypi", "version": "==3.0.0" }, "dateparser": { diff --git a/scripts/supervisord.conf b/scripts/supervisord.conf index d3ff288de..cb6fd1650 100644 --- a/scripts/supervisord.conf +++ b/scripts/supervisord.conf @@ -6,8 +6,8 @@ logfile_maxbytes=50MB ; max main logfile bytes b4 rotation; default 50MB logfile_backups=10 ; # of main logfile backups; 0 means none, default 10 loglevel=info ; log level; default info; others: debug,warn,trace -[program:gunicorn] -command=gunicorn -c /usr/src/paperless/gunicorn.conf.py -b 0.0.0.0:8000 paperless.wsgi +[program:daphne] +command=daphne -b 0.0.0.0 -p 8000 paperless.asgi:application user=paperless stdout_logfile=/dev/stdout diff --git a/src/paperless/asgi.py b/src/paperless/asgi.py index 9c3d17b1b..45565c68a 100644 --- a/src/paperless/asgi.py +++ b/src/paperless/asgi.py @@ -1,31 +1,17 @@ -import json import os -from asgiref.sync import async_to_sync -from channels.auth import AuthMiddlewareStack -from channels.generic.websocket import WebsocketConsumer -from channels.routing import ProtocolTypeRouter, URLRouter from django.core.asgi import get_asgi_application -from django.urls import re_path +# Fetch Django ASGI application early to ensure AppRegistry is populated +# before importing consumers and AuthMiddlewareStack that may import ORM +# models. -os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'paperless.settings') +os.environ.setdefault("DJANGO_SETTINGS_MODULE", "paperless.settings") +django_asgi_app = get_asgi_application() +from channels.auth import AuthMiddlewareStack +from channels.routing import ProtocolTypeRouter, URLRouter -class StatusConsumer(WebsocketConsumer): - def connect(self): - self.accept() - async_to_sync(self.channel_layer.group_add)('status_updates', self.channel_name) - - def disconnect(self, close_code): - async_to_sync(self.channel_layer.group_discard)('status_updates', self.channel_name) - - def status_update(self, event): - self.send(json.dumps(event['data'])) - - -websocket_urlpatterns = [ - re_path(r'ws/status/$', StatusConsumer.as_asgi()), -] +from paperless.urls import websocket_urlpatterns application = ProtocolTypeRouter({ "http": get_asgi_application(), diff --git a/src/paperless/consumers.py b/src/paperless/consumers.py new file mode 100644 index 000000000..fbb7b72d0 --- /dev/null +++ b/src/paperless/consumers.py @@ -0,0 +1,16 @@ +import json + +from asgiref.sync import async_to_sync +from channels.generic.websocket import WebsocketConsumer + + +class StatusConsumer(WebsocketConsumer): + def connect(self): + self.accept() + async_to_sync(self.channel_layer.group_add)('status_updates', self.channel_name) + + def disconnect(self, close_code): + async_to_sync(self.channel_layer.group_discard)('status_updates', self.channel_name) + + def status_update(self, event): + self.send(json.dumps(event['data'])) diff --git a/src/paperless/settings.py b/src/paperless/settings.py index c9db3e4b1..7ef132bff 100644 --- a/src/paperless/settings.py +++ b/src/paperless/settings.py @@ -307,7 +307,7 @@ CHANNEL_LAYERS = { "default": { "BACKEND": "channels_redis.core.RedisChannelLayer", "CONFIG": { - "hosts": [("127.0.0.1", 6379)], + "hosts": [("broker", 6379)], }, }, } diff --git a/src/paperless/urls.py b/src/paperless/urls.py index 43ba5eb49..4416bc8d5 100755 --- a/src/paperless/urls.py +++ b/src/paperless/urls.py @@ -1,11 +1,12 @@ from django.conf.urls import include, url from django.contrib import admin -from django.urls import path +from django.urls import path, re_path from django.views.decorators.csrf import csrf_exempt from django.views.generic import RedirectView from rest_framework.authtoken import views from rest_framework.routers import DefaultRouter +from paperless.consumers import StatusConsumer from paperless.views import FaviconView from documents.views import ( CorrespondentViewSet, @@ -65,6 +66,11 @@ urlpatterns = [ ] + +websocket_urlpatterns = [ + re_path(r'ws/status/$', StatusConsumer.as_asgi()), +] + # Text in each page's

(and above login form). admin.site.site_header = 'Paperless' # Text at the end of each page's .