Commit 1d41141d authored by David Seaward's avatar David Seaward

add celery configuration (with supervisor and django_celery_beat)

parent 774fb92f
# Site-specific ignores
purist_account/settings_local.py
docs/api/
*.pid
# Byte-compiled / optimized / DLL files
__pycache__/
......
......@@ -19,6 +19,7 @@ Prerequisites
* `libldap2-dev`
* `libssl-dev`
* `python3-dev`
* `supervisor`
* Additional uWSGI packages:
* `uwsgi`
* `uwsgi-emperor`
......@@ -75,14 +76,20 @@ Setup
* Hook up uWSGI:
* `sudo apt install uwsgi uwsgi-emperor uwsgi-plugin-python3`
* `cp ./conf/uwsgi_emperor_vassals/purist_account.ini /etc/uwsgi-emperor/vassals/`
* Hook up Supervisor (supervisord):
* `sudo apt install supervisor`
* `cp ./conf/supervisord/purist_account_monitor.conf /etc/supervisor/conf.d/`
* Restart services:
* `sudo service uwsgi-emperor restart`
* `sudo service nginx restart`
* `sudo service supervisor restart`
* Check logs:
* `/var/log/uwsgi/emperor.log`
* `/var/log/uwsgi/app/purist_account.log`
* `/var/log/nginx/error.log`
* `/var/log/nginx/access.log`
* `/var/log/supervisor/supervisord.log`
* `/var/log/purist/account/beat.log`
For more options and details see
<https://docs.djangoproject.com/en/1.11/#the-development-process>
......@@ -144,3 +151,5 @@ Also includes code portions from:
(Copyright 2015 Anders Hofstee and contributors, Expat/MIT)
* https://github.com/asyd/pyldap_orm/blob/master/pyldap_orm/controls.py
(Copyright 2016 Bruno Bonfils, Apache 2.0)
* https://github.com/celery/celery/blob/master/extra/supervisord/celerybeat.conf
(Copyright 2009-2012, 2015-2016 Ask Solem and contributors, 2012-2014 GoPivotal, Inc, BSD 3-Clause)
; stored as /etc/supervisor/conf.d/purist_account_monitor.conf
; Copyright 2017 Purism SPC and contributors
; SPDX-License-Identifier: GPL-3.0+
; Adapted from extra/supervisord/celerybeat.conf in Celery
; Copyright 2012-2014 GoPivotal, Inc.
; Copyright 2009-2012, 2015-2016 Ask Solem and contributors
; https://github.com/celery/celery/blob/master/extra/supervisord/celerybeat.conf
; SPDX-License-Identifier: BSD-3-Clause
[program:purist_account_monitor]
command=/opt/purist/account_virtualenv/bin/celery beat --app purist_account_monitor --scheduler django_celery_beat.schedulers:DatabaseScheduler --loglevel=INFO
directory=/opt/purist/account_web
user=www-data
numprocs=1
stdout_logfile=/var/log/purist/account/beat.log
stderr_logfile=/var/log/purist/account/beat.log
autostart=true
autorestart=true
startsecs=10
; if rabbitmq is supervised, set its priority higher
; so it starts first
priority=999
from celery import shared_task
@shared_task
def debug_task(self):
print('Limit monitor')
from .celery import app as celery_app
__all__ = ['celery_app']
# Copyright 2017 Purism SPC and contributors
# SPDX-License-Identifier: GPL-3.0+
# Original file from Celery 4.0.2 documentation
# Copyright 2009-2016 Ask Solem
# http://docs.celeryproject.org/en/latest/django/first-steps-with-django.html
# SPDX-License-Identifier: CC-BY-SA-4.0
import os
from celery import Celery
# set the default Django settings module for the 'celery' program.
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'purist_account.settings')
app = Celery('purist_account_monitor')
# Using a string here means the worker don't have to serialize
# the configuration object to child processes.
# - namespace='CELERY' means all celery-related configuration keys
# should have a `CELERY_` prefix.
app.config_from_object('django.conf:settings', namespace='CELERY')
# Load task modules from all registered Django app configs.
app.autodiscover_tasks()
@app.task(bind=True)
def debug_task(self):
print('Request: {0!r}'.format(self.request))
......@@ -32,8 +32,7 @@ ALLOWED_HOSTS = config("ALLOWED_HOSTS", cast=Csv())
# REGISTRATION APPLICATION
#
# INSTALLED_APPS = ["registration_defaults", ] + INSTALLED_APPS + ["ldapregister", ]
INSTALLED_APPS += ["crispy_forms", "ldapregister", "limitmonitor", ]
INSTALLED_APPS += ["crispy_forms", "django_celery_beat", "ldapregister", "limitmonitor", ]
REGISTRATION_OPEN = config("REGISTRATION_OPEN", cast=bool)
......
......@@ -2,6 +2,7 @@ Django==1.11.3
Jinja2==2.9.6
WooCommerce==1.2.1
celery==4.0.2
django-celery-beat==1.0.1
dj-database-url==0.4.2
django-auth-ldap==1.2.13
django-crispy-forms==1.6.1
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment