This commit is contained in:
yumoqing 2026-05-24 20:44:31 +08:00
parent 489ba1ad88
commit 686b05d8fe

View File

@ -244,38 +244,19 @@ async def backup_accounted_llmusage(cutoff_date):
env = ServerEnv() env = ServerEnv()
ts = env.timestampstr() ts = env.timestampstr()
batched = 0 batched = 0
recs = []
async with get_sor_context(env, 'llmage') as sor: async with get_sor_context(env, 'llmage') as sor:
sql = """select * from llmusage sql = """select * from llmusage
where accounting_status='accounted' where accounting_status='accounted'
and use_date < ${cutoff_date}$""" and use_date < ${cutoff_date}$"""
recs = await sor.sqlExe(sql, {'cutoff_date': cutoff_date}) recs = await sor.sqlExe(sql, {'cutoff_date': cutoff_date})
if not recs: if not recs:
debug(f'backup_accounted_llmusage: no records to backup for use_date < {cutoff_date}') debug(f'backup_accounted_llmusage: no records to backup for use_date < {cutoff_date}')
return 0 return 0
debug(f'backup_accounted_llmusage: {len(recs)} records to backup') debug(f'backup_accounted_llmusage: {cutoff_date} {len(recs)} records to backup')
for r in recs: for r in recs:
history_rec = { async with get_sor_context(env, 'llmage') as sor:
'id': r.id, await sor.C('llmusage_history', r.copy())
'llmid': r.llmid,
'use_date': r.use_date,
'use_time': r.use_time,
'userid': r.userid,
'usages': r.usages,
'ioinfo': r.ioinfo,
'transno': r.transno,
'responsed_seconds': r.responsed_seconds,
'finish_seconds': r.finish_seconds,
'status': r.status,
'taskid': r.taskid,
'amount': r.amount,
'cost': r.cost,
'userorgid': r.userorgid,
'ownerid': r.ownerid,
'accounting_status': r.accounting_status,
'backup_time': ts
}
await sor.C('llmusage_history', history_rec)
# Delete from main table
await sor.D('llmusage', {'id': r.id}) await sor.D('llmusage', {'id': r.id})
batched += 1 batched += 1
debug(f'backup_accounted_llmusage: backed up {batched} records for use_date < {cutoff_date}') debug(f'backup_accounted_llmusage: backed up {batched} records for use_date < {cutoff_date}')