Skip to content

Commit

Permalink
DSEGOG-179 Add flag to turn background Scheduler on/off
Browse files Browse the repository at this point in the history
  • Loading branch information
MRichards99 committed May 12, 2023
1 parent 555c4cb commit 750221a
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 4 deletions.
2 changes: 2 additions & 0 deletions .github/ci_config.yml
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions operationsgateway_api/config.yml.example
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions operationsgateway_api/src/config.py
Expand Up @@ -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
Expand Down
11 changes: 7 additions & 4 deletions operationsgateway_api/src/main.py
Expand Up @@ -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")
Expand Down

0 comments on commit 750221a

Please sign in to comment.