understanding commited on
Commit
4b81f85
·
verified ·
1 Parent(s): f828f12

Update main.py

Browse files
Files changed (1) hide show
  1. main.py +30 -6
main.py CHANGED
@@ -1,20 +1,44 @@
1
  # main.py
2
- import asyncio
3
- import logging
4
  import uvicorn
5
  from fastapi import FastAPI
6
- from bot import dp, bot, on_startup, main_loop_task
 
 
 
7
 
8
  app = FastAPI()
9
 
10
  @app.on_event("startup")
11
  async def startup_event():
 
12
  logging.info("Starting bot polling in background...")
13
- asyncio.create_task(main_loop_task())
14
 
15
  @app.get("/health")
16
- async def health():
17
  return {"status": "ok"}
18
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
19
  if __name__ == "__main__":
20
- uvicorn.run("main:app", host="0.0.0.0", port=7860, reload=False)
 
1
  # main.py
2
+
 
3
  import uvicorn
4
  from fastapi import FastAPI
5
+ from fastapi.responses import HTMLResponse
6
+ import logging
7
+ import asyncio
8
+ import bot # import your bot.py file
9
 
10
  app = FastAPI()
11
 
12
  @app.on_event("startup")
13
  async def startup_event():
14
+ logging.basicConfig(level=logging.INFO)
15
  logging.info("Starting bot polling in background...")
16
+ asyncio.create_task(bot.run_bot())
17
 
18
  @app.get("/health")
19
+ def health():
20
  return {"status": "ok"}
21
 
22
+ @app.get("/")
23
+ def home():
24
+ active_workers = bot.config.CONCURRENT_WORKERS
25
+ running_batches = len(bot.BATCH_JOBS)
26
+ queued_tasks = bot.TASK_QUEUE.qsize()
27
+
28
+ html = f"""
29
+ <html>
30
+ <head><title>Terabox Bot Status</title></head>
31
+ <body>
32
+ <h1>Terabox Bot Status</h1>
33
+ <p><b>Bot Username:</b> {bot.bot_username or 'Unknown'}</p>
34
+ <p><b>Active Workers:</b> {active_workers}</p>
35
+ <p><b>Running Batches:</b> {running_batches}</p>
36
+ <p><b>Queued Tasks:</b> {queued_tasks}</p>
37
+ <p><b>Health:</b> <a href="/health">/health</a></p>
38
+ </body>
39
+ </html>
40
+ """
41
+ return HTMLResponse(content=html)
42
+
43
  if __name__ == "__main__":
44
+ uvicorn.run(app, host="0.0.0.0", port=7860)