Skip to content

Commit ac96d65

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

File tree

3 files changed

+18
-2
lines changed

3 files changed

+18
-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: 16 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,20 @@ 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+
# Set the stop condition when receiving SIGTERM.
194+
loop = asyncio.get_running_loop()
195+
stop = loop.create_future()
196+
loop.add_signal_handler(signal.SIGTERM, stop.set_result, None)
197+
198+
port = int(os.environ.get("PORT", "8001"))
199+
async with serve(handler, "", port, process_request=health_check):
200+
await stop
187201

188202

189203
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)