refactor: update task refund logic and remove legacy handling

This commit is contained in:
CaIon
2026-07-26 20:47:52 +08:00
parent 2d23cdf291
commit bc14c18f60
6 changed files with 64 additions and 310 deletions
+3 -3
View File
@@ -162,7 +162,7 @@ func taskModelName(task *model.Task) string {
// RefundTaskQuota 统一的任务失败退款逻辑。
// 当异步任务失败时,将预扣的 quota 退还给用户(支持钱包和订阅),并退还令牌额度。
// 返回资金来源是否已成功退还;失败时保留 quota 作为后续对账标记
// 返回资金来源是否已成功退还;失败时保留 quota,供显式重试或人工对账
func RefundTaskQuota(ctx context.Context, task *model.Task, reason string) bool {
quota := task.Quota
if quota == 0 {
@@ -194,8 +194,8 @@ func RefundTaskQuota(ctx context.Context, task *model.Task, reason string) bool
Other: other,
})
// 4. 资金退款完成后再清除持久化标记;失败时保留非零 quota
// 由后续对账重试。回写失败必须显式告警,避免漏掉潜在的重复退款风险。
// 4. 资金退款完成后再清除持久化标记
// 回写失败必须显式告警,避免漏掉潜在的重复退款风险。
task.Quota = 0
if err := task.UpdateQuota(); err != nil {
logger.LogError(ctx, fmt.Sprintf("退款成功但清除 task quota 失败 task %s: %s", task.TaskID, err.Error()))