From 7104dd79b1550fa982079512a0b9eac0990225e7 Mon Sep 17 00:00:00 2001 From: donny-wong <141858744+donny-wong@users.noreply.github.com> Date: Tue, 24 Sep 2024 16:53:07 -0400 Subject: [PATCH] Add status API route for monitoring server status (#555) --- Changelog.md | 1 + client/autotest_client/__init__.py | 5 +++++ client/autotest_client/tests/test_flask_app.py | 13 +++++++++++++ 3 files changed, 19 insertions(+) diff --git a/Changelog.md b/Changelog.md index 1936f169..8398024f 100644 --- a/Changelog.md +++ b/Changelog.md @@ -3,6 +3,7 @@ All notable changes to this project will be documented here. ## [unreleased] - Haskell Tests - allow displaying of compilation errors (#554) +- Add status api for monitoring if Gunicorn is down (#555) ## [v2.5.1] - Ensure all Haskell test cases still run within same file when there are failed test cases (#543) diff --git a/client/autotest_client/__init__.py b/client/autotest_client/__init__.py index 87455aae..d9b73068 100644 --- a/client/autotest_client/__init__.py +++ b/client/autotest_client/__init__.py @@ -319,3 +319,8 @@ def cancel_tests(settings_id, **_kw): for id_, job in zip(test_ids, _get_jobs(test_ids, settings_id)): result[id_] = job if job is None else job.cancel() return jsonify(success=True) + + +@app.route("/status", methods=["GET"]) +def status(): + return jsonify(success=True) diff --git a/client/autotest_client/tests/test_flask_app.py b/client/autotest_client/tests/test_flask_app.py index 87a6c081..5fca42af 100644 --- a/client/autotest_client/tests/test_flask_app.py +++ b/client/autotest_client/tests/test_flask_app.py @@ -38,3 +38,16 @@ def test_api_key_set(self, response): def test_credentials_set(self, response, fake_redis_conn, credentials): assert json.loads(fake_redis_conn.hget("autotest:user_credentials", response.json["api_key"])) == credentials + + +class TestStatus: + + @pytest.fixture + def response(self, client): + return client.get("/status") + + def test_status_code(self, response): + assert response.status_code == 200 + + def test_success(self, response): + assert response.json["success"] is True