init
Browse files
app.py
CHANGED
|
@@ -61,6 +61,26 @@ async def startup_event():
|
|
| 61 |
# Start the bot in a separate thread to prevent blocking
|
| 62 |
threading.Thread(target=start_bot).start()
|
| 63 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 64 |
@app.get("/", response_class=HTMLResponse)
|
| 65 |
async def read_root(request: Request):
|
| 66 |
endpoints = get_ngrok_tunnels()
|
|
@@ -68,22 +88,4 @@ async def read_root(request: Request):
|
|
| 68 |
return templates.TemplateResponse(
|
| 69 |
"index.html",
|
| 70 |
{"request": request, "endpoints": endpoints, "css": css}
|
| 71 |
-
)
|
| 72 |
-
|
| 73 |
-
|
| 74 |
-
if __name__ == "__main__":
|
| 75 |
-
# Determine the port for Gunicorn
|
| 76 |
-
BASE_URL_PORT = determine_port()
|
| 77 |
-
|
| 78 |
-
# Start Gunicorn to run FastAPI app
|
| 79 |
-
logging.info("Starting Gunicorn server...")
|
| 80 |
-
gunicorn_command = f"gunicorn app:app --bind 0.0.0.0:{BASE_URL_PORT} --worker-class gevent"
|
| 81 |
-
gunicorn_process = Popen(gunicorn_command, shell=True)
|
| 82 |
-
|
| 83 |
-
# Start the alive script
|
| 84 |
-
logging.info("Starting alive script...")
|
| 85 |
-
alive_process = Popen(["python", "alive.py"])
|
| 86 |
-
|
| 87 |
-
# Optionally wait for processes to complete if desired (e.g., for graceful shutdown)
|
| 88 |
-
gunicorn_process.wait()
|
| 89 |
-
alive_process.wait()
|
|
|
|
| 61 |
# Start the bot in a separate thread to prevent blocking
|
| 62 |
threading.Thread(target=start_bot).start()
|
| 63 |
|
| 64 |
+
# Function to start external processes (Gunicorn and alive script)
|
| 65 |
+
def start_processes():
|
| 66 |
+
BASE_URL_PORT = determine_port()
|
| 67 |
+
|
| 68 |
+
# Start Gunicorn to run FastAPI app
|
| 69 |
+
logging.info("Starting Gunicorn server...")
|
| 70 |
+
gunicorn_command = f"gunicorn app:app --bind 0.0.0.0:{BASE_URL_PORT} --worker-class gevent"
|
| 71 |
+
gunicorn_process = Popen(gunicorn_command, shell=True)
|
| 72 |
+
|
| 73 |
+
# Start the alive script
|
| 74 |
+
logging.info("Starting alive script...")
|
| 75 |
+
alive_process = Popen(["python", "alive.py"])
|
| 76 |
+
|
| 77 |
+
# Optionally wait for processes to complete if desired (e.g., for graceful shutdown)
|
| 78 |
+
gunicorn_process.wait()
|
| 79 |
+
alive_process.wait()
|
| 80 |
+
|
| 81 |
+
# Start the external processes in a separate thread
|
| 82 |
+
threading.Thread(target=start_processes).start()
|
| 83 |
+
|
| 84 |
@app.get("/", response_class=HTMLResponse)
|
| 85 |
async def read_root(request: Request):
|
| 86 |
endpoints = get_ngrok_tunnels()
|
|
|
|
| 88 |
return templates.TemplateResponse(
|
| 89 |
"index.html",
|
| 90 |
{"request": request, "endpoints": endpoints, "css": css}
|
| 91 |
+
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|