Muttered3 commited on
Commit
30e9d64
·
verified ·
1 Parent(s): a7f0c46

Update dummy_server.py

Browse files
Files changed (1) hide show
  1. dummy_server.py +26 -12
dummy_server.py CHANGED
@@ -1,15 +1,29 @@
1
  import asyncio
2
- from aiohttp import web
 
 
 
 
3
 
4
- async def handle(request):
5
- return web.Response(text="OK", status=200)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
6
 
7
- async def run_server():
8
- app = web.Application()
9
- app.router.add_get("/{path_info:.*}", handle)
10
- runner = web.AppRunner(app)
11
- await runner.setup()
12
- site = web.TCPSite(runner, "0.0.0.0", 7860)
13
- await site.start()
14
- print("[SERVER] Dummy HTTP server running on port 7860")
15
- await asyncio.Event().wait()
 
1
  import asyncio
2
+ import os
3
+ from dummy_server import run_server
4
+ from bot import app
5
+ from worker import run_worker
6
+ from pyrogram import idle
7
 
8
+ async def main():
9
+ # 1. Start the dummy web server so Hugging Face keeps the Space awake on port 7860
10
+ print("🌐 Starting Dummy Server...")
11
+ asyncio.create_task(run_server())
12
+
13
+ # 2. Start the Pyrogram Bot
14
+ print("🤖 Starting Pyrogram Bot...")
15
+ await app.start()
16
+
17
+ # 3. Start the Sniper Workers
18
+ print("🚀 Firing up Sniper Workers...")
19
+ asyncio.create_task(run_worker())
20
+
21
+ # 4. Keep the process alive forever
22
+ await idle()
23
+
24
+ # Cleanup on shutdown
25
+ await app.stop()
26
 
27
+ if __name__ == "__main__":
28
+ # Pyrogram's app.run() handles the async event loop perfectly
29
+ app.run(main())