diff --git a/bin/backend_accounting.py b/bin/backend_accounting.py index f94c072..25f4265 100644 --- a/bin/backend_accounting.py +++ b/bin/backend_accounting.py @@ -17,6 +17,8 @@ from appPublic.folderUtils import ProgramPath from appPublic.jsonConfig import getConfig from sqlor.dbpools import DBPools from appPublic.log import MyLogger, debug, exception, info +from accounting.init import load_accounting +from llmage.init import load_llmage # 初始化配置 p = ProgramPath() @@ -25,31 +27,9 @@ DBPools(config.databases) # 导入 llmage 的计费函数 from llmage.accounting import ( - get_accounting_llmusages, - llm_accounting, - llm_accoung_failed + backend_accounting ) -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(): logger = MyLogger('backend_accounting', levelname='info', 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.SIGINT, handle_signal) - + load_accounting() try: loop.run_until_complete(backend_accounting()) except asyncio.CancelledError: