Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions model/task.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
3 changes: 2 additions & 1 deletion relay/channel/task/ali/adaptor.go
Original file line number Diff line number Diff line change
Expand Up @@ -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秒
}

Expand Down
3 changes: 3 additions & 0 deletions service/task_billing.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down