Skip to content

Commit

Permalink
Use preload in gunicorn
Browse files Browse the repository at this point in the history
  • Loading branch information
sondregronas committed Jul 26, 2024
1 parent 424f57e commit 6517b39
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 12 deletions.
7 changes: 3 additions & 4 deletions BookingSystem/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,14 +127,13 @@ def debug_login() -> flask.Response:
Compress(app)
Minify(app, static=False, go=False) # Some static files don't minify well (breaks JS)

init_db()
Settings.verify_settings_exist()
start_routine()

return app


app = create_app()
init_db()
Settings.verify_settings_exist()
start_routine() # Will not run if TESTING is set to True in the environment variables

if __name__ == '__main__':
app.run(host='0.0.0.0')
8 changes: 1 addition & 7 deletions BookingSystem/routine_tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,17 +39,11 @@ def _routine_backup():


def start_routine():
# Skip routine tasks in testing environment
if os.getenv('TESTING', 'false').lower() == 'true':
logger.info("Skipping routine tasks in testing environment")
return

if os.path.exists('/tmp/feideutstyrbase.pid'):
with open('/tmp/feideutstyrbase.pid', 'r') as f:
pid = int(f.read())
if os.getpid() != pid:
logger.info("Skipping routine tasks on worker process")
return

def _task(job_func):
try:
job_func()
Expand Down
2 changes: 1 addition & 1 deletion entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ run_app() {
cp -r /overrides/* /app;
fi

gunicorn --bind 0.0.0.0:5000 -t 60 -p /tmp/feideutstyrbase.pid app:app &
gunicorn --bind 0.0.0.0:5000 -t 60 -p /tmp/feideutstyrbase.pid --preload app:app &
PID=$!
wait $PID
}
Expand Down

0 comments on commit 6517b39

Please sign in to comment.