Skip to content

Commit

Permalink
🔖 Update to v1.4.11
Browse files Browse the repository at this point in the history
add watchdog
  • Loading branch information
omg-xtao committed Mar 12, 2024
1 parent aaa0aaa commit 557000d
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 4 deletions.
4 changes: 2 additions & 2 deletions pagermaid/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@
import pyromod.listen
from pyrogram import Client

pgm_version = "1.4.10"
pgm_version_code = 1410
pgm_version = "1.4.11"
pgm_version_code = 1411
CMD_LIST = {}
module_dir = __path__[0]
working_dir = getcwd()
Expand Down
36 changes: 34 additions & 2 deletions pagermaid/modules/reload.py
Original file line number Diff line number Diff line change
@@ -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.enums import Message
from pagermaid.listener import listener
from pagermaid.services import scheduler
from pagermaid.services import bot, scheduler
from pagermaid.utils import lang

ping_watchdog_event = asyncio.Event()


@listener(
is_plugin=False, command="reload", need_admin=True, description=lang("reload_des")
Expand All @@ -18,3 +24,29 @@ async def reload_plugins(message: Message):
@scheduler.scheduled_job("cron", hour="4", id="reload.clear_read_context")
async def clear_read_context_cron():
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")

0 comments on commit 557000d

Please sign in to comment.