From c2d068149b49a2f5255585b469d4d41083361fd8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sondre=20Gr=C3=B8n=C3=A5s?= <44143748+sondregronas@users.noreply.github.com> Date: Fri, 26 Jul 2024 13:05:23 +0200 Subject: [PATCH] Use preload for routines --- BookingSystem/app.py | 6 ++---- BookingSystem/routine_tasks.py | 3 --- entrypoint.sh | 2 +- requirements.txt | 1 - 4 files changed, 3 insertions(+), 9 deletions(-) diff --git a/BookingSystem/app.py b/BookingSystem/app.py index 42edc04..39841e5 100644 --- a/BookingSystem/app.py +++ b/BookingSystem/app.py @@ -129,12 +129,10 @@ def debug_login() -> flask.Response: init_db() Settings.verify_settings_exist() - start_routine() return app -app = create_app() - if __name__ == '__main__': - app.run(host='0.0.0.0') + start_routine() + create_app().run(host='0.0.0.0') diff --git a/BookingSystem/routine_tasks.py b/BookingSystem/routine_tasks.py index 83b5bec..2ccdcc5 100644 --- a/BookingSystem/routine_tasks.py +++ b/BookingSystem/routine_tasks.py @@ -43,9 +43,6 @@ def start_routine(): logger.info("Skipping routine tasks in testing environment") return - if os.getpid() != int(os.getenv('GUNICORN_PID')): - return - def _task(job_func): try: job_func() diff --git a/entrypoint.sh b/entrypoint.sh index 7a9b437..4b7a7ca 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 app:app & + gunicorn --bind 0.0.0.0:5000 --preload routine_tasks:start_routine() -t 60 app:create_app() & PID=$! wait $PID } diff --git a/requirements.txt b/requirements.txt index 130f2da..70ae8a6 100644 --- a/requirements.txt +++ b/requirements.txt @@ -11,4 +11,3 @@ MarkupSafe==2.1.5 pymsteams==0.2.2 flask-compress==1.15 schedule==1.2.2 -gunicorn==22.0.0