-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmain.py
More file actions
43 lines (29 loc) · 940 Bytes
/
main.py
File metadata and controls
43 lines (29 loc) · 940 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
import os
import time
import signal
import sys
from fastapi import FastAPI
app = FastAPI(title="Velos Example — FastAPI")
start_time = time.time()
@app.get("/")
def root():
return {
"message": "Hello from Velos!",
"pid": os.getpid(),
"env": os.getenv("APP_ENV", "default"),
}
@app.get("/health")
def health():
return {"status": "ok", "uptime": round(time.time() - start_time, 2)}
def handle_sigterm(signum, frame):
print("SIGTERM received, shutting down gracefully...")
sys.exit(0)
signal.signal(signal.SIGTERM, handle_sigterm)
if __name__ == "__main__":
import uvicorn
# Uvicorn logs to stderr by default, which makes velos tag them as [ERR].
# Redirect stderr to stdout so all output appears as normal log lines.
sys.stderr = sys.stdout
host = os.getenv("HOST", "0.0.0.0")
port = int(os.getenv("PORT", "8000"))
uvicorn.run(app, host=host, port=port)