Skip to content
Snippets Groups Projects
Commit 61788f2b authored by Todd Dembrey's avatar Todd Dembrey
Browse files

Tidy up the wsgi entry points (inc whitenoise)

parent 985c1292
No related branches found
No related tags found
No related merge requests found
......@@ -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'),
......
......@@ -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()
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')
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment