支持服务启动后自动预热转图浏览器
变更项:1) markdown_to_image 新增预热方法 warmup_md2img_browser/warmup_md2img_browser_sync,用于提前拉起常驻浏览器。2) main.py 启动流程新增后台预热线程,服务启动后自动执行转图浏览器预热。3) 预热失败仅记录日志不阻塞主服务,运行期仍可按需自动重建浏览器。4) 补充中文注释说明预热目的与降级策略。
This commit is contained in:
15
main.py
15
main.py
@@ -5,6 +5,7 @@ import threading
|
||||
|
||||
from admin.GlancesMonitor import GlancesMonitor
|
||||
from utils.decorator.async_job import async_job
|
||||
from utils.markdown_to_image import warmup_md2img_browser_sync
|
||||
from configuration import Config
|
||||
from robot import Robot
|
||||
|
||||
@@ -106,6 +107,20 @@ def main():
|
||||
except Exception as e:
|
||||
robot.LOG.error(f"GlancesMonitor服务器启动失败: {e}")
|
||||
|
||||
# 启动后异步预热 Markdown 转图浏览器,降低首个转图任务冷启动失败概率。
|
||||
try:
|
||||
def _warmup_md2img():
|
||||
ok = warmup_md2img_browser_sync(timeout_seconds=60)
|
||||
if ok:
|
||||
robot.LOG.info("Markdown 转图浏览器预热成功")
|
||||
else:
|
||||
robot.LOG.warning("Markdown 转图浏览器预热失败,运行期将按需重试")
|
||||
|
||||
warmup_thread = threading.Thread(target=_warmup_md2img, daemon=True)
|
||||
warmup_thread.start()
|
||||
except Exception as e:
|
||||
robot.LOG.error(f"启动 Markdown 转图预热线程失败: {e}")
|
||||
|
||||
robot.LOG.info(f"=" * 50)
|
||||
asyncio.run(async_job.run_all())
|
||||
# 让机器人一直跑
|
||||
|
||||
Reference in New Issue
Block a user