оптимизировал проверку зависших заданий
This commit is contained in:
+15
-3
@@ -1,6 +1,5 @@
|
|||||||
import asyncio
|
import asyncio
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
import os
|
|
||||||
import socket
|
import socket
|
||||||
import aiofiles
|
import aiofiles
|
||||||
import call_handler
|
import call_handler
|
||||||
@@ -38,6 +37,8 @@ async def full_log(event):
|
|||||||
|
|
||||||
|
|
||||||
async def ami_listening():
|
async def ami_listening():
|
||||||
|
callhandler = call_handler.CallHandler()
|
||||||
|
|
||||||
# процедура регулярной проверки соединения
|
# процедура регулярной проверки соединения
|
||||||
async def check_connection():
|
async def check_connection():
|
||||||
while True:
|
while True:
|
||||||
@@ -53,6 +54,18 @@ async def ami_listening():
|
|||||||
conn_check_task = asyncio.create_task(check_connection())
|
conn_check_task = asyncio.create_task(check_connection())
|
||||||
conn_check_task.add_done_callback(lambda t: ami_listening() if t.result() else None)
|
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:
|
while True:
|
||||||
try:
|
try:
|
||||||
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
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"
|
events_action = "Action: Events\r\nEventMask: on\r\n\r\n"
|
||||||
send_action(s, events_action)
|
send_action(s, events_action)
|
||||||
|
|
||||||
callhandler = call_handler.CallHandler()
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
while True:
|
while True:
|
||||||
event = send_action(s, "")
|
event = send_action(s, "")
|
||||||
@@ -87,6 +98,7 @@ async def ami_listening():
|
|||||||
except (KeyboardInterrupt, SystemExit):
|
except (KeyboardInterrupt, SystemExit):
|
||||||
logging.info("Exiting...")
|
logging.info("Exiting...")
|
||||||
s.close()
|
s.close()
|
||||||
|
daily_check_pending_task.cancel()
|
||||||
except ConnectionResetError:
|
except ConnectionResetError:
|
||||||
logging.warning("Connection reset. Restarting...")
|
logging.warning("Connection reset. Restarting...")
|
||||||
await ami_listening()
|
await ami_listening()
|
||||||
|
|||||||
@@ -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 +0,0 @@
|
|||||||
/medods_crz/.venv/bin/python /medods_crz/check_pending.py
|
|
||||||
Reference in New Issue
Block a user