fix: use add_startup() for cache_sync instead of asyncio.create_task

- init() is called synchronously before the event loop starts
  (configuredServer.py:36), so asyncio.create_task() fails with
  'no running event loop'
- Use ahserver's add_startup() which appends to app.on_startup
  and runs after the loop is ready (configuredServer.py:118)
- Remove unused asyncio import
This commit is contained in:
yumoqing 2026-05-26 17:16:18 +08:00
parent 5cbd8535dd
commit bc5e0f5e82

View File

@ -1,6 +1,5 @@
import os, sys
import json
import asyncio
import argparse
from appPublic.log import MyLogger, info, debug, warning
from appPublic.folderUtils import ProgramPath
@ -10,7 +9,7 @@ from appPublic.registerfunction import RegisterFunction
from bricks_for_python.init import load_pybricks
from ahserver.webapp import webapp
from ahserver.serverenv import ServerEnv
from ahserver.configuredServer import add_cleanupctx
from ahserver.configuredServer import add_cleanupctx, add_startup
from rbac.init import load_rbac, start_cache_sync
from pricing.init import load_pricing
from appbase.init import load_appbase
@ -42,7 +41,7 @@ def init():
load_pybricks()
load_appbase()
load_rbac()
asyncio.create_task(start_cache_sync())
add_startup(start_cache_sync)
load_accounting()
load_unipay()
load_platformbiz()