Skip to content

Commit

Permalink
Try using a pidfile
Browse files Browse the repository at this point in the history
  • Loading branch information
sondregronas committed Jul 26, 2024
1 parent 0d91639 commit 424f57e
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 2 deletions.
2 changes: 1 addition & 1 deletion BookingSystem/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,12 +129,12 @@ def debug_login() -> flask.Response:

init_db()
Settings.verify_settings_exist()
start_routine()

return app


app = create_app()

if __name__ == '__main__':
start_routine()
app.run(host='0.0.0.0')
7 changes: 7 additions & 0 deletions BookingSystem/routine_tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,13 @@ def start_routine():
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 --preload routine_tasks:start_routine() app:app &
gunicorn --bind 0.0.0.0:5000 -t 60 -p /tmp/feideutstyrbase.pid app:app &
PID=$!
wait $PID
}
Expand Down

0 comments on commit 424f57e

Please sign in to comment.