This commit is contained in:
yumoqing 2026-05-21 18:38:34 +08:00
parent 57d602bd54
commit feb966cba4

View File

@ -17,6 +17,8 @@ from appPublic.folderUtils import ProgramPath
from appPublic.jsonConfig import getConfig from appPublic.jsonConfig import getConfig
from sqlor.dbpools import DBPools from sqlor.dbpools import DBPools
from appPublic.log import MyLogger, debug, exception, info from appPublic.log import MyLogger, debug, exception, info
from accounting.init import load_accounting
from llmage.init import load_llmage
# 初始化配置 # 初始化配置
p = ProgramPath() p = ProgramPath()
@ -25,31 +27,9 @@ DBPools(config.databases)
# 导入 llmage 的计费函数 # 导入 llmage 的计费函数
from llmage.accounting import ( from llmage.accounting import (
get_accounting_llmusages, backend_accounting
llm_accounting,
llm_accoung_failed
) )
async def backend_accounting():
"""LLM 使用计费循环"""
info('backend accounting started ...')
while True:
try:
lus = await get_accounting_llmusages()
except Exception as e:
exception(f'{e}')
lus = []
debug(f'{len(lus)=} need to accounting........')
for lu in lus:
try:
debug(f'backend_accounting(): {lu.id=} handleing...')
await llm_accounting(lu)
except Exception as e:
exception(f'{e}, {lu.id=}')
await llm_accoung_failed(lu.id)
await asyncio.sleep(10)
def main(): def main():
logger = MyLogger('backend_accounting', levelname='info', logger = MyLogger('backend_accounting', levelname='info',
logfile=os.path.join(os.getcwd(), 'logs', 'backend_accounting.log')) logfile=os.path.join(os.getcwd(), 'logs', 'backend_accounting.log'))
@ -66,7 +46,7 @@ def main():
signal.signal(signal.SIGTERM, handle_signal) signal.signal(signal.SIGTERM, handle_signal)
signal.signal(signal.SIGINT, handle_signal) signal.signal(signal.SIGINT, handle_signal)
load_accounting()
try: try:
loop.run_until_complete(backend_accounting()) loop.run_until_complete(backend_accounting())
except asyncio.CancelledError: except asyncio.CancelledError: