Ok updated
Browse files- chatbot/__main__.py +20 -4
chatbot/__main__.py
CHANGED
@@ -39,6 +39,17 @@ logging.getLogger("pyrogram.syncer").setLevel(logging.WARNING)
|
|
39 |
logging.getLogger("pyrogram.client").setLevel(logging.WARNING)
|
40 |
loop = asyncio.get_event_loop()
|
41 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
42 |
async def premium_expiry_monitor(client):
|
43 |
while True:
|
44 |
try:
|
@@ -61,7 +72,8 @@ async def premium_expiry_monitor(client):
|
|
61 |
)
|
62 |
|
63 |
await asyncio.sleep(3600)
|
64 |
-
|
|
|
65 |
except Exception as e:
|
66 |
LOGS.error(f"Premium monitor error: {e}")
|
67 |
await asyncio.sleep(600)
|
@@ -89,7 +101,9 @@ async def process_unfreezes(client):
|
|
89 |
)
|
90 |
|
91 |
await asyncio.sleep(300)
|
92 |
-
|
|
|
|
|
93 |
except Exception as e:
|
94 |
LOGS.error(f"Unfreeze task error: {str(e)}")
|
95 |
await asyncio.sleep(60)
|
@@ -110,8 +124,7 @@ async def main():
|
|
110 |
randydev = Randydev(loop=loop)
|
111 |
|
112 |
await randydev.start()
|
113 |
-
|
114 |
-
asyncio.create_task(process_unfreezes(randydev))
|
115 |
LOGS.info("Application startup complete")
|
116 |
|
117 |
await idle()
|
@@ -120,6 +133,9 @@ async def main():
|
|
120 |
LOGS.critical(f"Fatal error: {str(e)}")
|
121 |
traceback.print_exc()
|
122 |
finally:
|
|
|
|
|
|
|
123 |
await shutdown(asyncio.get_event_loop())
|
124 |
|
125 |
if __name__ == "__main__":
|
|
|
39 |
logging.getLogger("pyrogram.client").setLevel(logging.WARNING)
|
40 |
loop = asyncio.get_event_loop()
|
41 |
|
42 |
+
async def startup_tasks(bot_client):
|
43 |
+
task1 = asyncio.create_task(
|
44 |
+
premium_expiry_monitor(bot_client),
|
45 |
+
name="premium_expiry_monitor"
|
46 |
+
)
|
47 |
+
task2 = asyncio.create_task(
|
48 |
+
process_unfreezes(bot_client),
|
49 |
+
name="process_unfreezes"
|
50 |
+
)
|
51 |
+
return [task1, task2]
|
52 |
+
|
53 |
async def premium_expiry_monitor(client):
|
54 |
while True:
|
55 |
try:
|
|
|
72 |
)
|
73 |
|
74 |
await asyncio.sleep(3600)
|
75 |
+
except asyncio.CancelledError:
|
76 |
+
LOGS.info("Premium monitor stopped gracefully")
|
77 |
except Exception as e:
|
78 |
LOGS.error(f"Premium monitor error: {e}")
|
79 |
await asyncio.sleep(600)
|
|
|
101 |
)
|
102 |
|
103 |
await asyncio.sleep(300)
|
104 |
+
|
105 |
+
except asyncio.CancelledError:
|
106 |
+
LOGS.info("Unfreeze monitor stopped gracefully")
|
107 |
except Exception as e:
|
108 |
LOGS.error(f"Unfreeze task error: {str(e)}")
|
109 |
await asyncio.sleep(60)
|
|
|
124 |
randydev = Randydev(loop=loop)
|
125 |
|
126 |
await randydev.start()
|
127 |
+
bg_tasks = await startup_tasks(randydev)
|
|
|
128 |
LOGS.info("Application startup complete")
|
129 |
|
130 |
await idle()
|
|
|
133 |
LOGS.critical(f"Fatal error: {str(e)}")
|
134 |
traceback.print_exc()
|
135 |
finally:
|
136 |
+
for task in bg_tasks:
|
137 |
+
task.cancel()
|
138 |
+
await asyncio.gather(*bg_tasks, return_exceptions=True)
|
139 |
await shutdown(asyncio.get_event_loop())
|
140 |
|
141 |
if __name__ == "__main__":
|