Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
phsl
/
new-api
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Members
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
b70b4597
authored
Oct 16, 2025
by
CaIon
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix: prevent duplicate refunds on task failure #2050
parent
6df44134
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
18 additions
and
9 deletions
+18
-9
controller/task_video.go
+17
-8
logger/logger.go
+1
-1
No files found.
controller/task_video.go
View file @
b70b4597
...
...
@@ -115,6 +115,12 @@ func updateVideoSingleTask(ctx context.Context, adaptor channel.TaskAdaptor, cha
//return fmt.Errorf("task %s status is empty", taskId)
taskResult
=
relaycommon
.
FailTaskInfo
(
"upstream returned empty status"
)
}
// 记录原本的状态,防止重复退款
shouldRefund
:=
false
quota
:=
task
.
Quota
preStatus
:=
task
.
Status
task
.
Status
=
model
.
TaskStatus
(
taskResult
.
Status
)
switch
taskResult
.
Status
{
case
model
.
TaskStatusSubmitted
:
...
...
@@ -225,7 +231,7 @@ func updateVideoSingleTask(ctx context.Context, adaptor channel.TaskAdaptor, cha
}
}
case
model
.
TaskStatusFailure
:
preStatus
:=
task
.
Status
logger
.
LogJson
(
ctx
,
fmt
.
Sprintf
(
"Task %s failed"
,
taskId
),
task
)
task
.
Status
=
model
.
TaskStatusFailure
task
.
Progress
=
"100%"
if
task
.
FinishTime
==
0
{
...
...
@@ -233,16 +239,10 @@ func updateVideoSingleTask(ctx context.Context, adaptor channel.TaskAdaptor, cha
}
task
.
FailReason
=
taskResult
.
Reason
logger
.
LogInfo
(
ctx
,
fmt
.
Sprintf
(
"Task %s failed: %s"
,
task
.
TaskID
,
task
.
FailReason
))
quota
:=
task
.
Quota
taskResult
.
Progress
=
"100%"
if
quota
!=
0
{
if
preStatus
!=
model
.
TaskStatusFailure
{
// 任务失败且之前状态不是失败才退还额度,防止重复退还
if
err
:=
model
.
IncreaseUserQuota
(
task
.
UserId
,
quota
,
false
);
err
!=
nil
{
logger
.
LogWarn
(
ctx
,
"Failed to increase user quota: "
+
err
.
Error
())
}
logContent
:=
fmt
.
Sprintf
(
"Video async task failed %s, refund %s"
,
task
.
TaskID
,
logger
.
LogQuota
(
quota
))
model
.
RecordLog
(
task
.
UserId
,
model
.
LogTypeSystem
,
logContent
)
shouldRefund
=
true
}
else
{
logger
.
LogWarn
(
ctx
,
fmt
.
Sprintf
(
"Task %s already in failure status, skip refund"
,
task
.
TaskID
))
}
...
...
@@ -257,6 +257,15 @@ func updateVideoSingleTask(ctx context.Context, adaptor channel.TaskAdaptor, cha
common
.
SysLog
(
"UpdateVideoTask task error: "
+
err
.
Error
())
}
if
shouldRefund
{
// 任务失败且之前状态不是失败才退还额度,防止重复退还
if
err
:=
model
.
IncreaseUserQuota
(
task
.
UserId
,
quota
,
false
);
err
!=
nil
{
logger
.
LogWarn
(
ctx
,
"Failed to increase user quota: "
+
err
.
Error
())
}
logContent
:=
fmt
.
Sprintf
(
"Video async task failed %s, refund %s"
,
task
.
TaskID
,
logger
.
LogQuota
(
quota
))
model
.
RecordLog
(
task
.
UserId
,
model
.
LogTypeSystem
,
logContent
)
}
return
nil
}
...
...
logger/logger.go
View file @
b70b4597
...
...
@@ -153,5 +153,5 @@ func LogJson(ctx context.Context, msg string, obj any) {
LogError
(
ctx
,
fmt
.
Sprintf
(
"json marshal failed: %s"
,
err
.
Error
()))
return
}
Log
Info
(
ctx
,
fmt
.
Sprintf
(
"%s | %s"
,
msg
,
string
(
jsonStr
)))
Log
Debug
(
ctx
,
fmt
.
Sprintf
(
"%s | %s"
,
msg
,
string
(
jsonStr
)))
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment