Skip to content

Commit

Permalink
Add a dedicated manual maintenance mode flag
Browse files Browse the repository at this point in the history
Currently, manually enabling database maintenance mode is awkward, as by
default it will just get switch off again by the regular automatic
check. So you have to remember to stop that first, which is awkward,
then restart it, for more awkwardness

Instead, this change adds an explicit flag check for
`manual-db-maintenance` - if that is set, we skip the automated check
altogether.

This will be added to the jobrunner justfile in backend-server as
a documented command in a separate PR.
  • Loading branch information
bloodearnest committed Oct 11, 2024
1 parent 0d3805a commit e8d1067
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
8 changes: 8 additions & 0 deletions jobrunner/service.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,14 @@ def maintenance_mode():
"""Check if the db is currently in maintenance mode, and set flags as appropriate."""
# This did not seem big enough to warrant splitting into a separate module.
log.info("checking if db undergoing maintenance...")

# manually setting this flag bypasses the automaticaly check
manual_db_mode = get_flag_value("manual-db-maintenance")
if manual_db_mode:
log.info(f"manually set db mode: db-maintenance")
return "db-maintenance"

# detect db mode from TPP.
current = get_flag_value("mode")
ps = docker(
[
Expand Down
5 changes: 5 additions & 0 deletions tests/test_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,11 @@ def test_maintenance_mode_error(mock_subprocess_run, db, db_config):
service.maintenance_mode()


def test_maintenance_mode_manual(db, db_config):
queries.set_flag("manual-db-maintenance", "on")
assert service.maintenance_mode() == "db-maintenance"


@pytest.fixture
def db_config(monkeypatch):
monkeypatch.setitem(config.DATABASE_URLS, "default", "mssql://localhost")

0 comments on commit e8d1067

Please sign in to comment.