mirror of
https://github.com/Xtao-Labs/twitter2telegram.git
synced 2024-11-21 22:58:08 +00:00
fix: use Lock to update task
This commit is contained in:
parent
20fae6ded6
commit
274b26ff29
@ -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()
|
||||||
|
Loading…
Reference in New Issue
Block a user