From 7df115e001e8fa3576c25f13184431bec77841da Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=A4=9A=E7=BE=85=E7=8B=BC?= Date: Sat, 30 Nov 2024 23:12:00 +0800 Subject: [PATCH] fix --- bots/api/bot.py | 1 + core/bot_init.py | 1 + core/queue.py | 6 ++++-- core/utils/web_render.py | 17 ++++++++++------- schedulers/init.py | 17 ----------------- 5 files changed, 16 insertions(+), 26 deletions(-) delete mode 100644 schedulers/init.py diff --git a/bots/api/bot.py b/bots/api/bot.py index 34f480c19e..02d025debc 100644 --- a/bots/api/bot.py +++ b/bots/api/bot.py @@ -34,6 +34,7 @@ async def startup_event(): load_extra_schedulers() Scheduler.start() await JobQueue.secret_append_ip() + await JobQueue.web_render_status() @app.get('/auth/{token}') diff --git a/core/bot_init.py b/core/bot_init.py index 79f7d11d20..e4fc1754e9 100644 --- a/core/bot_init.py +++ b/core/bot_init.py @@ -34,6 +34,7 @@ async def init_async(start_scheduler=True) -> None: if not Info.subprocess: load_extra_schedulers() await JobQueue.secret_append_ip() + await JobQueue.web_render_status() Scheduler.start() logging.getLogger('apscheduler.executors.default').setLevel(logging.WARNING) await load_secret() diff --git a/core/queue.py b/core/queue.py index a5ab087ff5..69d42d94cd 100644 --- a/core/queue.py +++ b/core/queue.py @@ -12,6 +12,7 @@ from core.logger import Logger from core.utils.info import get_all_clients_name from core.utils.ip import append_ip, fetch_ip_info +from core.utils.web_render import check_web_render _queue_tasks = {} queue_actions = {} @@ -70,10 +71,11 @@ async def secret_append_ip(cls): await cls.add_job(target, 'secret_append_ip', ip_info, wait=False) @classmethod - async def web_render_status(cls, web_render_status: bool, web_render_local_status: bool): + async def web_render_status(cls): + web_render_status, web_render_local_status = await check_web_render() for target in get_all_clients_name(): await cls.add_job(target, 'web_render_status', {'web_render_status': web_render_status, - 'web_render_local_status': web_render_local_status}) + 'web_render_local_status': web_render_local_status}, wait=False) @classmethod async def send_message(cls, target_client: str, target_id: str, message): diff --git a/core/utils/web_render.py b/core/utils/web_render.py index bd93b2e00e..8cd6975982 100644 --- a/core/utils/web_render.py +++ b/core/utils/web_render.py @@ -1,5 +1,5 @@ import traceback -from typing import Union +from typing import Tuple, Union from core.config import Config from core.constants.info import Info @@ -32,17 +32,19 @@ def webrender(method: str = '', url: str = '', use_local: bool = True) -> Union[ return None -async def check_web_render(): +async def check_web_render() -> Tuple[bool, bool]: + web_render_status = False + web_render_local_status = False if not web_render_local: if not web_render: Logger.warning('[WebRender] WebRender is not configured.') else: - Info.web_render_status = True + web_render_status = True else: - Info.web_render_local_status = True - Info.web_render_status = True + web_render_status = True + web_render_local_status = True ping_url = 'http://www.bing.com' - if Info.web_render_status: + if web_render_status: try: Logger.info('[WebRender] Checking WebRender status...') await get_url(webrender('source', ping_url), 200, request_private_ip=True) @@ -50,6 +52,7 @@ async def check_web_render(): except Exception: Logger.error('[WebRender] WebRender is not working as expected.') Logger.error(traceback.format_exc()) - Info.web_render_status = False + web_render_status = False + return web_render_status, web_render_local_status __all__ = ['webrender', 'check_web_render'] diff --git a/schedulers/init.py b/schedulers/init.py deleted file mode 100644 index 99dc3e19b2..0000000000 --- a/schedulers/init.py +++ /dev/null @@ -1,17 +0,0 @@ -from datetime import datetime, timedelta - -from core.constants import Info -from core.logger import Logger -from core.queue import JobQueue -from core.scheduler import DateTrigger, Scheduler -from core.utils.web_render import check_web_render - - -@Scheduler.scheduled_job(DateTrigger(datetime.now() + timedelta(seconds=10))) -async def check_webrender(): - Logger.info('Checking webrender...') - await check_web_render() - - await JobQueue.web_render_status(web_render_status=Info.web_render_status, - web_render_local_status=Info.web_render_local_status) - Logger.info('Successfully checked webrender.')