From 61788f2b892b1369830a0f94f22d2f59feda7324 Mon Sep 17 00:00:00 2001 From: Todd Dembrey <todd.dembrey@torchbox.com> Date: Wed, 29 Aug 2018 10:25:35 +0100 Subject: [PATCH] Tidy up the wsgi entry points (inc whitenoise) --- opentech/settings/base.py | 3 ++- opentech/wsgi.py | 7 +------ opentech/wsgi_cron.py | 38 -------------------------------------- 3 files changed, 3 insertions(+), 45 deletions(-) delete mode 100644 opentech/wsgi_cron.py diff --git a/opentech/settings/base.py b/opentech/settings/base.py index d92336480..e5284296b 100644 --- a/opentech/settings/base.py +++ b/opentech/settings/base.py @@ -82,6 +82,7 @@ INSTALLED_APPS = [ MIDDLEWARE = [ 'django.middleware.security.SecurityMiddleware', + 'whitenoise.middleware.WhiteNoiseMiddleware', 'django.contrib.sessions.middleware.SessionMiddleware', 'django.middleware.common.CommonMiddleware', 'django.middleware.csrf.CsrfViewMiddleware', @@ -201,7 +202,7 @@ SHORT_DATETIME_FORMAT = 'Y-m-d\TH:i:s' # Static files (CSS, JavaScript, Images) # https://docs.djangoproject.com/en/stable/howto/static-files/ -STATICFILES_STORAGE = 'django.contrib.staticfiles.storage.ManifestStaticFilesStorage' +STATICFILES_STORAGE = 'whitenoise.storage.CompressedManifestStaticFilesStorage' STATICFILES_DIRS = [ os.path.join(PROJECT_DIR, 'static_compiled'), diff --git a/opentech/wsgi.py b/opentech/wsgi.py index 4b557f1df..dce17d696 100644 --- a/opentech/wsgi.py +++ b/opentech/wsgi.py @@ -9,13 +9,8 @@ https://docs.djangoproject.com/en/1.8/howto/deployment/wsgi/ import os -from whitenoise.django import DjangoWhiteNoise - from django.core.wsgi import get_wsgi_application -from opentech.wsgi_cron import * # NOQA - - os.environ.setdefault("DJANGO_SETTINGS_MODULE", "opentech.settings.production") -application = DjangoWhiteNoise(get_wsgi_application()) +application = get_wsgi_application() diff --git a/opentech/wsgi_cron.py b/opentech/wsgi_cron.py deleted file mode 100644 index 7ff802573..000000000 --- a/opentech/wsgi_cron.py +++ /dev/null @@ -1,38 +0,0 @@ -import os - -from django.core.management import call_command - -try: - import uwsgi - from uwsgidecorators import timer, cron - - print("We have a uWSGI") - has_uwsgi = True -except ImportError: - print("We have no uWSGI") - has_uwsgi = False - - -def single_instance_command(command_name): - """Runs command only on one instance of a uWSGI legion""" - - if uwsgi.i_am_the_lord(os.getenv("CFG_APP_NAME")): - print("I am the lord.") - print("Running %s" % command_name) - call_command(command_name, interactive=False) - else: - print("I am not the lord.") - - -if has_uwsgi: - @cron(0, 1, -1, -1, 0) - def clearsessions(signum): - single_instance_command('clearsessions') - - @cron(0, 0, -1, -1, 0) - def update_index(signum): - single_instance_command('update_index') - - @timer(300) - def publish_scheduled_pages(cron): - single_instance_command('publish_scheduled_pages') -- GitLab