Skip to content

Commit 4a4b6e9

Browse files
committed
Deploy to Koyeb.
1 parent 7f0b2c4 commit 4a4b6e9

File tree

3 files changed

+15
-2
lines changed

3 files changed

+15
-2
lines changed

Procfile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
web: python app.py

app.py

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
11
#!/usr/bin/env python
22

33
import asyncio
4+
import http
45
import json
6+
import os
57
import secrets
8+
import signal
69

710
from websockets.asyncio.server import broadcast, serve
811

@@ -181,9 +184,17 @@ async def handler(websocket):
181184
await start(websocket)
182185

183186

187+
def health_check(connection, request):
188+
if request.path == "/healthz":
189+
return connection.respond(http.HTTPStatus.OK, "OK\n")
190+
191+
184192
async def main():
185-
async with serve(handler, "", 8001):
186-
await asyncio.get_running_loop().create_future() # run forever
193+
port = int(os.environ.get("PORT", "8001"))
194+
async with serve(handler, "", port, process_request=health_check) as server:
195+
loop = asyncio.get_running_loop()
196+
loop.add_signal_handler(signal.SIGTERM, server.close)
197+
await server.wait_closed()
187198

188199

189200
if __name__ == "__main__":

requirements.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
websockets

0 commit comments

Comments
 (0)