mirror of
https://github.com/TeamPGM/PagerMaid-Pyro.git
synced 2024-11-21 23:08:02 +00:00
🔖 Update to v1.4.11
add watchdog
This commit is contained in:
parent
aaa0aaaa16
commit
557000dbec
@ -22,8 +22,8 @@ from pagermaid.scheduler import scheduler
|
|||||||
import pyromod.listen
|
import pyromod.listen
|
||||||
from pyrogram import Client
|
from pyrogram import Client
|
||||||
|
|
||||||
pgm_version = "1.4.10"
|
pgm_version = "1.4.11"
|
||||||
pgm_version_code = 1410
|
pgm_version_code = 1411
|
||||||
CMD_LIST = {}
|
CMD_LIST = {}
|
||||||
module_dir = __path__[0]
|
module_dir = __path__[0]
|
||||||
working_dir = getcwd()
|
working_dir = getcwd()
|
||||||
|
@ -1,10 +1,16 @@
|
|||||||
from pagermaid import read_context
|
import asyncio
|
||||||
|
|
||||||
|
from pyrogram.raw.functions import PingDelayDisconnect
|
||||||
|
|
||||||
|
from pagermaid import read_context, logs
|
||||||
from pagermaid.common.reload import reload_all
|
from pagermaid.common.reload import reload_all
|
||||||
from pagermaid.enums import Message
|
from pagermaid.enums import Message
|
||||||
from pagermaid.listener import listener
|
from pagermaid.listener import listener
|
||||||
from pagermaid.services import scheduler
|
from pagermaid.services import bot, scheduler
|
||||||
from pagermaid.utils import lang
|
from pagermaid.utils import lang
|
||||||
|
|
||||||
|
ping_watchdog_event = asyncio.Event()
|
||||||
|
|
||||||
|
|
||||||
@listener(
|
@listener(
|
||||||
is_plugin=False, command="reload", need_admin=True, description=lang("reload_des")
|
is_plugin=False, command="reload", need_admin=True, description=lang("reload_des")
|
||||||
@ -18,3 +24,29 @@ async def reload_plugins(message: Message):
|
|||||||
@scheduler.scheduled_job("cron", hour="4", id="reload.clear_read_context")
|
@scheduler.scheduled_job("cron", hour="4", id="reload.clear_read_context")
|
||||||
async def clear_read_context_cron():
|
async def clear_read_context_cron():
|
||||||
read_context.clear()
|
read_context.clear()
|
||||||
|
|
||||||
|
|
||||||
|
@scheduler.scheduled_job("interval", seconds=10, id="reload.ping_watchdog")
|
||||||
|
async def ping_task():
|
||||||
|
if not bot.is_initialized:
|
||||||
|
return
|
||||||
|
if ping_watchdog_event.is_set():
|
||||||
|
logs.debug("Ping task watchdog event set, skip")
|
||||||
|
return
|
||||||
|
logs.debug("Ping task running")
|
||||||
|
try:
|
||||||
|
await bot.session.invoke(
|
||||||
|
PingDelayDisconnect(
|
||||||
|
ping_id=0,
|
||||||
|
disconnect_delay=bot.session.WAIT_TIMEOUT + 10,
|
||||||
|
),
|
||||||
|
retries=0,
|
||||||
|
)
|
||||||
|
except OSError:
|
||||||
|
logs.debug("Ping task raise OSError, try restart")
|
||||||
|
ping_watchdog_event.set()
|
||||||
|
try:
|
||||||
|
await bot.restart()
|
||||||
|
finally:
|
||||||
|
ping_watchdog_event.clear()
|
||||||
|
logs.debug("Ping task ok")
|
||||||
|
Loading…
Reference in New Issue
Block a user