-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathkeep_alive.py
More file actions
71 lines (53 loc) · 1.75 KB
/
keep_alive.py
File metadata and controls
71 lines (53 loc) · 1.75 KB
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
"""Keep-alive server for deployment platforms like Render, Railway, etc."""
from datetime import datetime
from logging import getLogger
from fastapi import FastAPI
from fastapi.responses import JSONResponse
import uvicorn
logger = getLogger(__name__)
app = FastAPI(title="Discord Bot Keep-Alive Server")
@app.get("/")
async def root():
"""Root endpoint for basic health check"""
return JSONResponse(
content={
"status": "ok",
"message": "Discord bot is running",
"timestamp": datetime.now().isoformat(),
}
)
@app.get("/health")
async def health_check():
"""Health check endpoint for monitoring services"""
return JSONResponse(
content={
"status": "healthy",
"service": "intech-discord-bot",
"timestamp": datetime.now().isoformat(),
}
)
@app.get("/ping")
async def ping():
"""Simple ping endpoint"""
return JSONResponse(content={"response": "pong"})
def run_server(host: str = "0.0.0.0", port: int = 8000):
"""Run the keep-alive server
Args:
host: Host address to bind to
port: Port number to listen on
"""
logger.info(f"Starting keep-alive server on {host}:{port}")
uvicorn.run(app, host=host, port=port, log_level="info")
async def run_server_async(host: str = "0.0.0.0", port: int = 8000):
"""Run the keep-alive server asynchronously
Args:
host: Host address to bind to
port: Port number to listen on
"""
config = uvicorn.Config(app, host=host, port=port, log_level="info")
server = uvicorn.Server(config)
logger.info(f"Starting keep-alive server on {host}:{port}")
await server.serve()
if __name__ == "__main__":
# Standalone execution
run_server()