From 24577f78c8dd88245f4acc37f2ff6046d2b7f6b6 Mon Sep 17 00:00:00 2001 From: manojdbos <141425445+manojdbos@users.noreply.github.com> Date: Tue, 22 Oct 2024 11:28:14 -0700 Subject: [PATCH] Deactivate admin api (#133) Stop the threads for: Scheduled workflows Queues Kafka --- dbos/admin_sever.py | 10 ++++++++++ tests/test_admin_server.py | 7 +++++++ 2 files changed, 17 insertions(+) diff --git a/dbos/admin_sever.py b/dbos/admin_sever.py index 63cfcc0d..2d344aa4 100644 --- a/dbos/admin_sever.py +++ b/dbos/admin_sever.py @@ -18,6 +18,7 @@ health_check_path = "/dbos-healthz" workflow_recovery_path = "/dbos-workflow-recovery" perf_path = "/dbos-perf" +deactivate_path = "/deactivate" class AdminServer: @@ -66,6 +67,15 @@ def do_GET(self) -> None: self.send_response(200) self._end_headers() self.wfile.write(json.dumps(perf_util).encode("utf-8")) + elif self.path == deactivate_path: + dbos_logger.info("Deactivating DBOS") + # Stop all scheduled workflows, queues, and kafka loops + for event in self.dbos.stop_events: + event.set() + + self.send_response(200) + self._end_headers() + self.wfile.write("deactivated".encode("utf-8")) else: self.send_response(404) self._end_headers() diff --git a/tests/test_admin_server.py b/tests/test_admin_server.py index 6a91eeb4..88fbe2b0 100644 --- a/tests/test_admin_server.py +++ b/tests/test_admin_server.py @@ -48,6 +48,13 @@ def test_admin_endpoints(dbos: DBOS) -> None: response = requests.post("http://localhost:3001/stuff", timeout=5) assert response.status_code == 404 + response = requests.get("http://localhost:3001/deactivate", timeout=5) + assert response.status_code == 200 + + for event in dbos.stop_events: + assert event.is_set(), "Event is not set!" + + def test_admin_recovery(dbos: DBOS) -> None: os.environ["DBOS__VMID"] = "testexecutor"