Skip to content
Merged
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
43 changes: 25 additions & 18 deletions core/app/task/task.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (

"github.com/1Panel-dev/1Panel/core/app/model"
"github.com/1Panel-dev/1Panel/core/app/repo"
"github.com/1Panel-dev/1Panel/core/buserr"
"github.com/1Panel-dev/1Panel/core/constant"
"github.com/1Panel-dev/1Panel/core/global"
"github.com/1Panel-dev/1Panel/core/i18n"
Expand All @@ -21,27 +22,29 @@ type ActionFunc func(*Task) error
type RollbackFunc func(*Task)

type Task struct {
Name string
TaskID string
Logger *log.Logger
SubTasks []*SubTask
Rollbacks []RollbackFunc
logFile *os.File
taskRepo repo.ITaskRepo
Task *model.Task
ParentID string
Name string
TaskID string
Logger *log.Logger
SubTasks []*SubTask
Rollbacks []RollbackFunc
logFile *os.File
taskRepo repo.ITaskRepo
Task *model.Task
ParentID string
CancleWhenTimeout bool
}

type SubTask struct {
RootTask *Task
Name string
StepAlias string
Retry int
Timeout time.Duration
Action ActionFunc
Rollback RollbackFunc
Error error
IgnoreErr bool
RootTask *Task
Name string
StepAlias string
Retry int
Timeout time.Duration
Action ActionFunc
Rollback RollbackFunc
Error error
IgnoreErr bool
CancleWhenTimeout bool
}

const (
Expand Down Expand Up @@ -143,6 +146,9 @@ func (s *SubTask) Execute() error {
select {
case <-ctx.Done():
s.RootTask.Log(i18n.GetWithName("TaskTimeout", subTaskName))
if s.CancleWhenTimeout {
return buserr.New(i18n.GetWithName("TaskTimeout", subTaskName))
}
case err = <-done:
if err != nil {
s.RootTask.Log(i18n.GetWithNameAndErr("SubTaskFailed", subTaskName, err))
Expand Down Expand Up @@ -173,6 +179,7 @@ func (t *Task) Execute() error {
var err error
t.Log(i18n.GetWithName("TaskStart", t.Name))
for _, subTask := range t.SubTasks {
subTask.CancleWhenTimeout = t.CancleWhenTimeout
t.Task.CurrentStep = subTask.StepAlias
t.updateTask(t.Task)
if err = subTask.Execute(); err == nil {
Expand Down
Loading