Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
DoroWolf committed Nov 30, 2024
1 parent a475dc0 commit 7df115e
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 26 deletions.
1 change: 1 addition & 0 deletions bots/api/bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -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}')
Expand Down
1 change: 1 addition & 0 deletions core/bot_init.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
6 changes: 4 additions & 2 deletions core/queue.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {}
Expand Down Expand Up @@ -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):
Expand Down
17 changes: 10 additions & 7 deletions core/utils/web_render.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -32,24 +32,27 @@ 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)
Logger.info('[WebRender] WebRender is working as expected.')
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']
17 changes: 0 additions & 17 deletions schedulers/init.py

This file was deleted.

0 comments on commit 7df115e

Please sign in to comment.