Skip to content

Commit

Permalink
Merge branch 'main' into madwort/increase-test-coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
madwort authored Oct 31, 2024
2 parents 8405801 + f4ec9b7 commit ee67100
Show file tree
Hide file tree
Showing 7 changed files with 25 additions and 34 deletions.
3 changes: 0 additions & 3 deletions .github/workflows/build_and_publish.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,6 @@ jobs:
build-and-publish-docker-image:
runs-on: ubuntu-latest
name: Build and publish docker image
# Only on a tagged release
needs: tag-new-version
if: needs.tag-new-version.outputs.tag
steps:
- name: Checkout
uses: actions/checkout@v4
Expand Down
2 changes: 2 additions & 0 deletions docker/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ RUN --mount=type=cache,target=/var/cache/apt \
# Install everything in venv for isolation from system python libraries
RUN python3 -m venv /opt/venv
ENV VIRTUAL_ENV=/opt/venv/ PATH="/opt/venv/bin:$PATH"
# jobrunner only works with bindmounts, not docker volumes
ENV LOCAL_VOLUME_API="jobrunner.executors.volumes:BindMountVolumeAPI"

# The cache mount means a) /root/.cache is not in the image, and b) it's preserved
# between docker builds locally, for faster dev rebuild.
Expand Down
19 changes: 15 additions & 4 deletions jobrunner/service.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,10 +89,21 @@ def maintenance_wrapper():
time.sleep(config.MAINTENANCE_POLL_INTERVAL)


DB_MAINTENANCE_MODE = "db-maintenance"


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_MODE}")
return DB_MAINTENANCE_MODE

# detect db mode from TPP.
current = get_flag_value("mode")
ps = docker(
[
Expand All @@ -111,14 +122,14 @@ def maintenance_mode():
text=True,
)
last_line = ps.stdout.strip().split("\n")[-1]
if "db-maintenance" in last_line:
if current != "db-maintenance":
if DB_MAINTENANCE_MODE in last_line:
if current != DB_MAINTENANCE_MODE:
log.warning("Enabling DB maintenance mode")
else:
log.warning("DB maintenance mode is currently enabled")
set_flag("mode", "db-maintenance")
set_flag("mode", DB_MAINTENANCE_MODE)
else:
if current == "db-maintenance":
if current == DB_MAINTENANCE_MODE:
log.info("DB maintenance mode had ended")
set_flag("mode", None)

Expand Down
20 changes: 0 additions & 20 deletions justfile
Original file line number Diff line number Diff line change
Expand Up @@ -181,23 +181,3 @@ run repo action: devenv
# required by docker-compose.yaml
dotenv:
cp dotenv-sample .env

update-wheels: devenv
#!/usr/bin/env bash
set -euo pipefail
if test -d lib; then
git -C lib pull
else
git clone [email protected]:opensafely/job-runner-dependencies.git lib
fi
# wipe clean to remove old packages and start fresh each time
rm lib/* -rf
# restore README.md, as we don't want to delete that
git -C lib checkout README.md

# Now install the dependencies
$BIN/pip install -U -r requirements.prod.txt -r requirements.tools.txt --target lib
cp requirements.prod.txt requirements.tools.txt lib/
# remove any .so libs
find lib/ -name \*.so -exec rm {} \;
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ classifiers = [
]
requires-python = ">=3.8"
dependencies = [
"opensafely-pipeline @ git+https://github.com/opensafely-core/[email protected].08.124104",
"opensafely-pipeline @ git+https://github.com/opensafely-core/[email protected].11.170331",
"ruyaml",
"requests",
"opentelemetry-exporter-otlp-proto-http",
Expand Down
8 changes: 2 additions & 6 deletions requirements.prod.txt
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ googleapis-common-protos==1.56.4
# via opentelemetry-exporter-otlp-proto-http
idna==2.10
# via requests
opensafely-pipeline @ git+https://github.com/opensafely-core/[email protected].08.124104
opensafely-pipeline @ git+https://github.com/opensafely-core/[email protected].11.170331
# via opensafely-jobrunner (pyproject.toml)
opentelemetry-api==1.12.0
# via
Expand All @@ -36,8 +36,6 @@ protobuf==3.20.2
# via
# googleapis-common-protos
# opentelemetry-proto
pydantic==1.10.12
# via opensafely-pipeline
requests==2.25.0
# via
# opensafely-jobrunner (pyproject.toml)
Expand All @@ -47,9 +45,7 @@ ruyaml==0.91.0
# opensafely-jobrunner (pyproject.toml)
# opensafely-pipeline
typing-extensions==4.7.1
# via
# opentelemetry-sdk
# pydantic
# via opentelemetry-sdk
urllib3==1.26.5
# via requests
wrapt==1.14.1
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 ee67100

Please sign in to comment.