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