diff --git a/.github/ci_config.yml b/.github/ci_config.yml index e372bff0..fe99f0a7 100644 --- a/.github/ci_config.yml +++ b/.github/ci_config.yml @@ -32,6 +32,8 @@ experiments: # contacting the Scheduler for the 'new experiments'. This setting is only used the # first time that experiments are being populated into the database first_scheduler_contact_start_date: 2019-01-02T00:00:00Z + # Flag to enable/disable the background task to contact the Scheduler + scheduler_background_task_enabled: false # Cron job string format. Every Monday at 9:00am - 0 9 * * 1 scheduler_background_frequency: 0 9 * * 1 # Timezones as per dateutil.tz. https://stackoverflow.com/a/15454186 provides a way of diff --git a/operationsgateway_api/config.yml.example b/operationsgateway_api/config.yml.example index f02102e3..46c6a638 100644 --- a/operationsgateway_api/config.yml.example +++ b/operationsgateway_api/config.yml.example @@ -38,6 +38,8 @@ experiments: # contacting the Scheduler for the 'new experiments'. This setting is only used the # first time that experiments are being populated into the database first_scheduler_contact_start_date: 2019-01-02T00:00:00Z + # Flag to enable/disable the background task to contact the Scheduler + scheduler_background_task_enabled: false # Cron job string format. Every Monday at 9:00am - 0 9 * * 1 scheduler_background_frequency: 0 9 * * 1 # Timezones as per dateutil.tz. https://stackoverflow.com/a/15454186 provides a way of diff --git a/operationsgateway_api/src/config.py b/operationsgateway_api/src/config.py index bacbae34..9453d630 100644 --- a/operationsgateway_api/src/config.py +++ b/operationsgateway_api/src/config.py @@ -59,6 +59,7 @@ class ExperimentsConfig(BaseModel): """Configuration model class to store experiment configuration details""" first_scheduler_contact_start_date: datetime + scheduler_background_task_enabled: StrictBool scheduler_background_frequency: StrictStr scheduler_background_timezone: StrictStr scheduler_background_retry_mins: float diff --git a/operationsgateway_api/src/main.py b/operationsgateway_api/src/main.py index 712b3066..12f6d078 100644 --- a/operationsgateway_api/src/main.py +++ b/operationsgateway_api/src/main.py @@ -67,10 +67,13 @@ def setup_logger(): @app.on_event("startup") async def get_experiments_on_startup(): - log.info( - "Creating task for Scheduler system to be contacted for experiment details", - ) - asyncio.create_task(runners.scheduler_runner.start_task()) + if Config.config.experiments.scheduler_background_task_enabled: + log.info( + "Creating task for Scheduler system to be contacted for experiment details", + ) + asyncio.create_task(runners.scheduler_runner.start_task()) + else: + log.info("Scheduler background task has not been enabled") @app.on_event("startup")