Spaces:
Paused
Paused
Update dummy_server.py
Browse files- dummy_server.py +26 -12
dummy_server.py
CHANGED
|
@@ -1,15 +1,29 @@
|
|
| 1 |
import asyncio
|
| 2 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3 |
|
| 4 |
-
async def
|
| 5 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 6 |
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
app.
|
| 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())
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|