mirror of
https://github.com/acepanel/panel.git
synced 2026-02-04 03:07:20 +08:00
feat: 防止任务重复提交
This commit is contained in:
@@ -8,6 +8,6 @@ import (
|
||||
)
|
||||
|
||||
func initQueue() {
|
||||
app.Queue = queue.New(40)
|
||||
app.Queue = queue.New(100)
|
||||
go app.Queue.Run(context.Background())
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package data
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"log/slog"
|
||||
"sync"
|
||||
|
||||
@@ -47,9 +48,18 @@ func (r *taskRepo) UpdateStatus(id uint, status biz.TaskStatus) error {
|
||||
}
|
||||
|
||||
func (r *taskRepo) Push(task *biz.Task) error {
|
||||
var count int64
|
||||
if err := app.Orm.Model(&biz.Task{}).Where("shell = ? and (status = ? or status = ?)", task.Shell, biz.TaskStatusWaiting, biz.TaskStatusRunning).Count(&count).Error; err != nil {
|
||||
return err
|
||||
}
|
||||
if count > 0 {
|
||||
return fmt.Errorf("任务重复提交,请等待上一个任务完成")
|
||||
}
|
||||
|
||||
if err := app.Orm.Create(task).Error; err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return app.Queue.Push(queuejob.NewProcessTask(r), []any{
|
||||
task.ID,
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user