From 96f6a926be415beb326e281fda9493c08aad8a2f Mon Sep 17 00:00:00 2001 From: Russell Ballestrini Date: Fri, 8 Aug 2025 22:35:35 -0400 Subject: [PATCH] Fix NameError and add feature flag for scheduler - Restored start_scheduler() function that was missing - Added DISABLE_SCHEDULER feature flag check in main() - App should start now without scheduler running - Fixed 500 Internal Server Error russell@unturf.com is the boss --- .gitlab-ci.yml | 2 +- app.py | 25 +++++++++++++++++++++++-- 2 files changed, 24 insertions(+), 3 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 4ee1da3..1eeb511 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -63,7 +63,7 @@ deploy: [Service] WorkingDirectory=${APP_DIR} - Environment="PATH=${VENV_DIR}/bin" + Environment="PATH=${VENV_DIR}/bin" "DISABLE_SCHEDULER=true" ExecStart=${VENV_DIR}/bin/uwsgi \\ --master \\ --enable-threads \\ diff --git a/app.py b/app.py index 328a760..f1c4644 100644 --- a/app.py +++ b/app.py @@ -889,6 +889,23 @@ def check_and_run_scheduler(): log.error(f"On-demand scheduler error: {e}") +def start_scheduler(): + """Start the background scheduler.""" + global scheduler_thread, scheduler_running + + # Check if scheduler is disabled via environment variable + disable_scheduler = os.environ.get('DISABLE_SCHEDULER', '').lower() in ('true', '1', 'yes') + if disable_scheduler: + log.info("Scheduler disabled by DISABLE_SCHEDULER environment variable") + return + + if not scheduler_running: + scheduler_running = True + scheduler_thread = threading.Thread(target=scheduler_worker, daemon=True) + scheduler_thread.start() + log.info("Scheduler started") + + def stop_scheduler(): """Stop the background scheduler.""" global scheduler_thread, scheduler_running @@ -2313,8 +2330,12 @@ def main(*config, **settings): config.scan() - # Start the scheduler - start_scheduler() + # Start the scheduler (with feature flag) + disable_scheduler = os.environ.get('DISABLE_SCHEDULER', '').lower() in ('true', '1', 'yes') + if not disable_scheduler: + start_scheduler() + else: + log.info("Scheduler disabled by DISABLE_SCHEDULER environment variable") return config.make_wsgi_app()