Skip to content

Commit

Permalink
use private wsgi file for Docker images
Browse files Browse the repository at this point in the history
  • Loading branch information
jrief committed Sep 29, 2016
1 parent 4760cce commit ac5eb63
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 34 deletions.
40 changes: 40 additions & 0 deletions example/docker-files/wsgi.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import os
from django.core.management import call_command
from django.core.wsgi import get_wsgi_application
try:
import uwsgidecorators

@uwsgidecorators.timer(15)
def send_queued_mail(num):
"""
Send queued mail every 15 seconds
"""
call_command('send_queued_mail')

@uwsgidecorators.cron(0, 6, -1, -1, -1)
def rebuild_index(num):
"""
Rebuild search index in the morning
"""
call_command('rebuild_index', interactive=False)

@uwsgidecorators.cron(30, 5, -1, -1, 0)
def shopcustomers(num):
"""
Delete expired customers every Sunday
"""
call_command('shopcustomers', delete_expired=True)

except ImportError:
print("uwsgidecorators not found. Cron and timers are disabled")

application = get_wsgi_application()

# rebuild full text search index on first bootstrap
BOOTSTRAP_FILE = os.path.join(os.getenv('DJANGO_WORKDIR', ''), '.bootstrap')
if os.path.isfile(BOOTSTRAP_FILE):
call_command('initialize_shop_demo', interactive=False)
call_command('compilescss')
call_command('collectstatic', interactive=False, ignore_patterns='*.scss')
call_command('rebuild_index', interactive=False)
os.remove(BOOTSTRAP_FILE)
34 changes: 0 additions & 34 deletions example/wsgi.py
Original file line number Diff line number Diff line change
@@ -1,37 +1,3 @@
import os
from django.core.management import call_command
from django.core.wsgi import get_wsgi_application
try:
import uwsgidecorators

@uwsgidecorators.timer(15)
def send_queued_mail(num):
"""
Send queued mail every 15 seconds
"""
call_command('send_queued_mail')

@uwsgidecorators.cron(0, 6, -1, -1, -1)
def rebuild_index(num):
"""
Rebuild search index in the morning
"""
call_command('rebuild_index', interactive=False)

@uwsgidecorators.cron(30, 5, -1, -1, 0)
def shopcustomers(num):
"""
Delete expired customers every Sunday
"""
call_command('shopcustomers', delete_expired=True)

except ImportError:
print("uwsgidecorators not found. Cron and timers are disabled")

application = get_wsgi_application()

# rebuild full text search index on first bootstrap
BOOTSTRAP_FILE = os.path.join(os.getenv('DJANGO_WORKDIR', ''), 'bootstrap')
if os.path.isfile(BOOTSTRAP_FILE):
call_command('rebuild_index', interactive=False)
os.remove(BOOTSTRAP_FILE)

0 comments on commit ac5eb63

Please sign in to comment.