оптимизировал проверку зависших заданий

This commit is contained in:
Dev PC
2025-08-03 18:04:48 +03:00
parent 2c88ae6e85
commit 18032bb712
3 changed files with 15 additions and 18 deletions
+15 -3
View File
@@ -1,6 +1,5 @@
import asyncio
from datetime import datetime
import os
import socket
import aiofiles
import call_handler
@@ -38,6 +37,8 @@ async def full_log(event):
async def ami_listening():
callhandler = call_handler.CallHandler()
# процедура регулярной проверки соединения
async def check_connection():
while True:
@@ -53,6 +54,18 @@ async def ami_listening():
conn_check_task = asyncio.create_task(check_connection())
conn_check_task.add_done_callback(lambda t: ami_listening() if t.result() else None)
# запуск check_pending ежедневно в 23:00
async def daily_check_pending():
while True:
now = datetime.now()
if now.hour == 23 and now.minute == 0 and now.second < 5:
await callhandler.check_pending()
await asyncio.sleep(60)
else:
await asyncio.sleep(1)
daily_check_pending_task = asyncio.create_task(daily_check_pending())
while True:
try:
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
@@ -75,8 +88,6 @@ async def ami_listening():
events_action = "Action: Events\r\nEventMask: on\r\n\r\n"
send_action(s, events_action)
callhandler = call_handler.CallHandler()
try:
while True:
event = send_action(s, "")
@@ -87,6 +98,7 @@ async def ami_listening():
except (KeyboardInterrupt, SystemExit):
logging.info("Exiting...")
s.close()
daily_check_pending_task.cancel()
except ConnectionResetError:
logging.warning("Connection reset. Restarting...")
await ami_listening()
-14
View File
@@ -1,14 +0,0 @@
import asyncio
import call_handler
callhandler = call_handler.CallHandler()
async def mailn():
await callhandler.check_pending()
return
if __name__ == "__main__":
asyncio.run(mailn())
-1
View File
@@ -1 +0,0 @@
/medods_crz/.venv/bin/python /medods_crz/check_pending.py