Skip to content

Commit 6c83f7c

Browse files
authored
Merge pull request #26 from QuLogic/webhook-health
Add a ping endpoint to webhook service
2 parents daf095f + ddd0b50 commit 6c83f7c

File tree

3 files changed

+25
-0
lines changed

3 files changed

+25
-0
lines changed

templates/Caddyfile.j2

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,16 @@ http://{{ caddy.addresses.webhook }} {
4646
}
4747
}
4848

49+
handle /ping {
50+
reverse_proxy * localhost:1234 {
51+
# Don't leak out internal problems.
52+
@error status 4xx 5xx
53+
handle_response @error {
54+
error 503
55+
}
56+
}
57+
}
58+
4959
handle {
5060
error 404
5161
}

webhook/test_webhook.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,15 @@ async def test_update_repo(tmp_path_factory):
6565
assert dest_commit == src_commit
6666

6767

68+
async def test_ping(aiohttp_client, monkeypatch, tmp_path):
69+
"""Test ping always works."""
70+
monkeypatch.setenv('SITE_DIR', str(tmp_path))
71+
client = await aiohttp_client(create_app())
72+
73+
resp = await client.get('/ping')
74+
assert resp.status == 200
75+
76+
6877
async def test_github_webhook_errors(aiohttp_client, monkeypatch, tmp_path):
6978
"""Test invalid inputs to webhook."""
7079
monkeypatch.setenv('SITE_DIR', str(tmp_path))

webhook/webhook.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,11 @@ async def github_webhook(request: web.Request):
173173
return web.Response(status=200)
174174

175175

176+
async def ping(request: web.Request):
177+
"""Respond to a ping, thus verifying the webhook service is alive."""
178+
return web.Response(status=200)
179+
180+
176181
def create_app():
177182
"""Create the aiohttp app and setup routes."""
178183
site_dir = Path(os.environ.get('SITE_DIR', 'sites')).resolve()
@@ -182,6 +187,7 @@ def create_app():
182187
app['site_dir'] = site_dir
183188
app.add_routes([
184189
web.post('/gh/{repo}', github_webhook),
190+
web.get('/ping', ping),
185191
])
186192
return app
187193

0 commit comments

Comments
 (0)