From 9894b5afa83d45ff11284a5e603e02032f68c91e Mon Sep 17 00:00:00 2001 From: Rojo Date: Mon, 6 Nov 2023 18:47:33 +0000 Subject: [PATCH] Added status endpoint for healthchecks and renamed dst_api_test to dst_api --- README.md | 6 +++--- app.py | 4 ++++ docker-compose.yaml | 2 +- dst_api_test.py => dst_api.py | 0 tests.py | 4 ++++ 5 files changed, 12 insertions(+), 4 deletions(-) rename dst_api_test.py => dst_api.py (100%) diff --git a/README.md b/README.md index 0179b19..518d140 100644 --- a/README.md +++ b/README.md @@ -44,13 +44,13 @@ docker-compose -f docker-compose.yaml up -d With this you can easily have the app and the api test running without more setup. ## Simulating an internal service -There's also a simple app in `dst_api_test.py` that receives requests on any path available and responds with `200`, to use it: +There's also a simple app in `dst_api.py` that receives requests on any path available and responds with `200`, to use it: ```bash -python dst_api_test.py +python dst_api.py ``` -This will give you a place to test the relay of webhooks, you can set the `RELAY_DST_URL` in your .env to localhost:50001. You can set a different port in the dst_api_test.py script. +This will give you a place to test the relay of webhooks, you can set the `RELAY_DST_URL` in your .env to localhost:50001. You can set a different port in the `dst_api.py` script. If you're using `docker-compose` this has already been configured. ## Development diff --git a/app.py b/app.py index e1ec085..1c28dbb 100644 --- a/app.py +++ b/app.py @@ -45,5 +45,9 @@ def webhook(subpath): logging.error(f"An error occurred in the main thread: {e}") return jsonify(success=False), 500 +@app.route('/status') +def status(): + return '', 200 + if __name__ == '__main__': app.run(host=os.environ.get("RELAY_HOST", "0.0.0.0"), port=os.environ.get("RELAY_PORT", 50000)) diff --git a/docker-compose.yaml b/docker-compose.yaml index 3cc56d5..0f57946 100644 --- a/docker-compose.yaml +++ b/docker-compose.yaml @@ -13,6 +13,6 @@ services: webhook-relay-test: container_name: webhook_relay_test build: . - command: gunicorn --access-logfile - -w 1 -b 0.0.0.0:50001 dst_api_test:app + command: gunicorn --access-logfile - -w 1 -b 0.0.0.0:50001 dst_api:app ports: - '50001:50001' diff --git a/dst_api_test.py b/dst_api.py similarity index 100% rename from dst_api_test.py rename to dst_api.py diff --git a/tests.py b/tests.py index d9021ef..3b45a18 100644 --- a/tests.py +++ b/tests.py @@ -39,5 +39,9 @@ def test_webhook_exception(self, mock_log, mock_thread): self.assertEqual(response.json, {'success': False}) mock_log.assert_called_once_with('An error occurred in the main thread: Test exception') + def test_status_endpoint(self): + response = self.client.get('/status') + self.assertEqual(response.status_code, 200) + if __name__ == '__main__': unittest.main()