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
04d441ef
authored
Oct 12, 2025
by
Seefs
Committed by
GitHub
Oct 12, 2025
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #2025 from feitianbubu/pr/protect-increase-quota
feat: Add pre-status protection for IncreaseUserQuota
parents
b48584d3
b3e6145c
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
11 additions
and
4 deletions
+11
-4
controller/task_video.go
+11
-4
No files found.
controller/task_video.go
View file @
04d441ef
...
@@ -214,6 +214,7 @@ func updateVideoSingleTask(ctx context.Context, adaptor channel.TaskAdaptor, cha
...
@@ -214,6 +214,7 @@ func updateVideoSingleTask(ctx context.Context, adaptor channel.TaskAdaptor, cha
}
}
}
}
case
model
.
TaskStatusFailure
:
case
model
.
TaskStatusFailure
:
preStatus
:=
task
.
Status
task
.
Status
=
model
.
TaskStatusFailure
task
.
Status
=
model
.
TaskStatusFailure
task
.
Progress
=
"100%"
task
.
Progress
=
"100%"
if
task
.
FinishTime
==
0
{
if
task
.
FinishTime
==
0
{
...
@@ -222,12 +223,18 @@ func updateVideoSingleTask(ctx context.Context, adaptor channel.TaskAdaptor, cha
...
@@ -222,12 +223,18 @@ func updateVideoSingleTask(ctx context.Context, adaptor channel.TaskAdaptor, cha
task
.
FailReason
=
taskResult
.
Reason
task
.
FailReason
=
taskResult
.
Reason
logger
.
LogInfo
(
ctx
,
fmt
.
Sprintf
(
"Task %s failed: %s"
,
task
.
TaskID
,
task
.
FailReason
))
logger
.
LogInfo
(
ctx
,
fmt
.
Sprintf
(
"Task %s failed: %s"
,
task
.
TaskID
,
task
.
FailReason
))
quota
:=
task
.
Quota
quota
:=
task
.
Quota
taskResult
.
Progress
=
"100%"
if
quota
!=
0
{
if
quota
!=
0
{
if
err
:=
model
.
IncreaseUserQuota
(
task
.
UserId
,
quota
,
false
);
err
!=
nil
{
if
preStatus
!=
model
.
TaskStatusFailure
{
logger
.
LogError
(
ctx
,
"Failed to increase user quota: "
+
err
.
Error
())
// 任务失败且之前状态不是失败才退还额度,防止重复退还
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
)
}
else
{
logger
.
LogWarn
(
ctx
,
fmt
.
Sprintf
(
"Task %s already in failure status, skip refund"
,
task
.
TaskID
))
}
}
logContent
:=
fmt
.
Sprintf
(
"Video async task failed %s, refund %s"
,
task
.
TaskID
,
logger
.
LogQuota
(
quota
))
model
.
RecordLog
(
task
.
UserId
,
model
.
LogTypeSystem
,
logContent
)
}
}
default
:
default
:
return
fmt
.
Errorf
(
"unknown task status %s for task %s"
,
taskResult
.
Status
,
taskId
)
return
fmt
.
Errorf
(
"unknown task status %s for task %s"
,
taskResult
.
Status
,
taskId
)
...
...
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