From 393ab40459f6ba87fc3b2a3ebf1f5d19689c3a72 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=B4=9B=E6=B0=B4=E5=B1=85=E5=AE=A4?= Date: Wed, 14 Dec 2022 23:34:44 +0800 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20Flush=20Cookies=20Cache=20on=20Init?= =?UTF-8?q?ialization?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- plugins/jobs/public_cookies.py | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/plugins/jobs/public_cookies.py b/plugins/jobs/public_cookies.py index df223e7d..eacd0a96 100644 --- a/plugins/jobs/public_cookies.py +++ b/plugins/jobs/public_cookies.py @@ -1,3 +1,4 @@ +import asyncio import datetime from telegram.ext import CallbackContext @@ -11,8 +12,16 @@ class PublicCookies(Plugin): def __init__(self, public_cookies_service: PublicCookiesService = None): self.public_cookies_service = public_cookies_service + async def __async_init__(self): + async def _refresh(): + logger.info("正在刷新公共Cookies池") + await self.public_cookies_service.refresh() + logger.success("刷新公共Cookies池成功") + + asyncio.create_task(_refresh()) + @job.run_repeating(interval=datetime.timedelta(hours=2), name="PublicCookiesRefresh") async def refresh(self, _: CallbackContext): logger.info("正在刷新公共Cookies池") await self.public_cookies_service.refresh() - logger.info("刷新公共Cookies池成功") + logger.success("刷新公共Cookies池成功")