fix: use Lock to update task

This commit is contained in:
xtaodada 2023-12-01 23:37:49 +08:00
parent 20fae6ded6
commit 274b26ff29
Signed by: xtaodada
GPG Key ID: 4CBB3F4FA8C85659

View File

@ -1,3 +1,5 @@
from asyncio import Lock
from pyrogram.types import Message from pyrogram.types import Message
from defs.glover import owner from defs.glover import owner
@ -8,14 +10,23 @@ from pyrogram import filters
from defs.update import check_update from defs.update import check_update
_lock = Lock()
@bot.on_message(filters=filters.command("check_update") & filters.user(owner)) @bot.on_message(filters=filters.command("check_update") & filters.user(owner))
async def update_all(_, message: Message): async def update_all(_, message: Message):
msg = await message.reply("开始检查更新!") if _lock.locked():
await check_update() await message.reply("正在检查更新,请稍后再试!")
await msg.edit("检查更新完毕!") return
async with _lock:
msg = await message.reply("开始检查更新!")
await check_update()
await msg.edit("检查更新完毕!")
@scheduler.scheduled_job("cron", minute="*/15", id="update_all") @scheduler.scheduled_job("cron", minute="*/15", id="update_all")
async def update_all_30_minutes(): async def update_all_15_minutes():
await check_update() if _lock.locked():
return
async with _lock:
await check_update()