From cb9e16371dae436c45e04f222537ed7bf64b1152 Mon Sep 17 00:00:00 2001 From: Klaus-Uwe Mitterer Date: Fri, 1 Feb 2019 16:49:55 +0000 Subject: [PATCH] Prepare for queue --- misc/celery.service | 12 ++++++++++++ setup.sh | 4 ++-- vpnmanager/__init__.py | 3 +++ vpnmanager/celery.py | 7 +++++++ vpnmanager/settings.py | 5 +++++ 5 files changed, 29 insertions(+), 2 deletions(-) create mode 100644 misc/celery.service create mode 100644 vpnmanager/celery.py diff --git a/misc/celery.service b/misc/celery.service new file mode 100644 index 0000000..194cee1 --- /dev/null +++ b/misc/celery.service @@ -0,0 +1,12 @@ +[Unit] +Description=Celery Service +After=network.target + +[Service] +User=vpn +Group=vpn +WorkingDirectory=/opt/vpnmanager +ExecStart=/bin/sh -c '/usr/local/bin/celery -A vpnmanager worker -l info' + +[Install] +WantedBy=multi-user.target diff --git a/setup.sh b/setup.sh index 962051d..222a34c 100644 --- a/setup.sh +++ b/setup.sh @@ -1,8 +1,8 @@ #!/bin/bash sudo apt update -sudo apt install -y python3-pip npm openvpn easy-rsa postfix -sudo pip3 install -U django django-cron uwsgi django-two-factor-auth django-bootstrap-form twilio argon2_cffi GitPython +sudo apt install -y python3-pip npm openvpn easy-rsa postfix rabbitmq-server +sudo pip3 install -U django django-cron uwsgi celery django-celery-results django-two-factor-auth django-bootstrap-form twilio argon2_cffi GitPython sudo useradd vpn git submodule init git submodule update diff --git a/vpnmanager/__init__.py b/vpnmanager/__init__.py index e69de29..b92e033 100644 --- a/vpnmanager/__init__.py +++ b/vpnmanager/__init__.py @@ -0,0 +1,3 @@ +from .celery import app as celery_app + +__all__ = ('celery_app', ) diff --git a/vpnmanager/celery.py b/vpnmanager/celery.py new file mode 100644 index 0000000..c5e8eed --- /dev/null +++ b/vpnmanager/celery.py @@ -0,0 +1,7 @@ +import os +from celery import Celery + +os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'vpnmanager.settings') +app = Celery('vpnmanager') +app.config_from_object('django.conf:settings', namespace='CELERY') +app.autodiscover_tasks() diff --git a/vpnmanager/settings.py b/vpnmanager/settings.py index d5856fb..392461b 100644 --- a/vpnmanager/settings.py +++ b/vpnmanager/settings.py @@ -23,6 +23,7 @@ TWILIO_CALLER_ID = "+43676800555559" INSTALLED_APPS = [ 'bootstrapform', 'django_otp', + 'django_celery_results', 'django_otp.plugins.otp_static', 'django_otp.plugins.otp_totp', 'two_factor', @@ -141,3 +142,7 @@ PASSWORD_HASHERS = [ CRON_CLASSES = [ "manager.cronjobs.FetchRemoteCron", ] + +# Celery config + +CELERY_RESULT_BACKEND = 'django-db'