Skip to content

Commit

Permalink
Added status endpoint for healthchecks and renamed dst_api_test to ds…
Browse files Browse the repository at this point in the history
…t_api
  • Loading branch information
rojosinalma committed Nov 6, 2023
1 parent 28cce3e commit 9894b5a
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 4 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions app.py
Original file line number Diff line number Diff line change
Expand Up @@ -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))
2 changes: 1 addition & 1 deletion docker-compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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'
File renamed without changes.
4 changes: 4 additions & 0 deletions tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()

0 comments on commit 9894b5a

Please sign in to comment.