From 043720f9bebfceb6bb7256d43e3a2e7eb02c43c3 Mon Sep 17 00:00:00 2001 From: feitianbubu Date: Mon, 6 Jul 2026 11:49:24 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BB=BB=E5=8A=A1=E5=B7=AE=E9=A2=9D?= =?UTF-8?q?=E7=BB=93=E7=AE=97=E5=90=8E=20quota=20=E5=92=8C=E9=98=BF?= =?UTF-8?q?=E9=87=8C=E8=A7=86=E9=A2=91=E6=97=B6=E9=95=BF=E4=BC=98=E5=8C=96?= =?UTF-8?q?=20(#5923)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * fix: apply default ali video duration when value is non-positive * fix: persist task quota after async settlement --- model/task.go | 4 ++++ relay/channel/task/ali/adaptor.go | 3 ++- service/task_billing.go | 3 +++ 3 files changed, 9 insertions(+), 1 deletion(-) diff --git a/model/task.go b/model/task.go index 9c0cb6dd..cf936ed1 100644 --- a/model/task.go +++ b/model/task.go @@ -417,6 +417,10 @@ func (Task *Task) Update() error { return err } +func (t *Task) UpdateQuota() error { + return DB.Model(t).Update("quota", t.Quota).Error +} + // UpdateWithStatus performs a conditional UPDATE guarded by fromStatus (CAS). // Returns (true, nil) if this caller won the update, (false, nil) if // another process already moved the task out of fromStatus. diff --git a/relay/channel/task/ali/adaptor.go b/relay/channel/task/ali/adaptor.go index f3645472..2b85c435 100644 --- a/relay/channel/task/ali/adaptor.go +++ b/relay/channel/task/ali/adaptor.go @@ -415,7 +415,8 @@ func (a *TaskAdaptor) convertToAliRequest(info *relaycommon.RelayInfo, req relay } else { aliReq.Parameters.Duration = seconds } - } else { + } + if aliReq.Parameters.Duration <= 0 { aliReq.Parameters.Duration = 5 // 默认5秒 } diff --git a/service/task_billing.go b/service/task_billing.go index 31e29e32..785a8675 100644 --- a/service/task_billing.go +++ b/service/task_billing.go @@ -215,6 +215,9 @@ func RecalculateTaskQuota(ctx context.Context, task *model.Task, actualQuota int taskAdjustTokenQuota(ctx, task, quotaDelta) task.Quota = actualQuota + if err := task.UpdateQuota(); err != nil { + logger.LogError(ctx, fmt.Sprintf("差额结算回写 quota 失败 task %s: %s", task.TaskID, err.Error())) + } var logType int var logQuota int