diff --git a/BookingSystem/app.py b/BookingSystem/app.py index 2931616..42edc04 100644 --- a/BookingSystem/app.py +++ b/BookingSystem/app.py @@ -129,6 +129,7 @@ def debug_login() -> flask.Response: init_db() Settings.verify_settings_exist() + start_routine() return app @@ -136,5 +137,4 @@ def debug_login() -> flask.Response: app = create_app() if __name__ == '__main__': - start_routine() app.run(host='0.0.0.0') diff --git a/BookingSystem/routine_tasks.py b/BookingSystem/routine_tasks.py index 2ccdcc5..707d052 100644 --- a/BookingSystem/routine_tasks.py +++ b/BookingSystem/routine_tasks.py @@ -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() diff --git a/entrypoint.sh b/entrypoint.sh index 53b87c6..5d3ffa9 100644 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -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 }