MCPcopy Create free account
hub / github.com/1Panel-dev/1Panel / Execute

Method Execute

core/app/task/task.go:135–177  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

133}
134
135func (s *SubTask) Execute() error {
136 subTaskName := s.Name
137 if s.Name == "" {
138 subTaskName = i18n.GetMsgByKey("SubTask")
139 }
140 s.RootTask.LogStart(subTaskName)
141 var err error
142 for i := 0; i < s.Retry+1; i++ {
143 if i > 0 {
144 s.RootTask.Log(i18n.GetWithName("TaskRetry", strconv.Itoa(i)))
145 }
146 ctx, cancel := context.WithTimeout(context.Background(), s.Timeout)
147 defer cancel()
148
149 done := make(chan error)
150 go func() {
151 done <- s.Action(s.RootTask)
152 }()
153
154 select {
155 case <-ctx.Done():
156 s.RootTask.Log(i18n.GetWithName("TaskTimeout", subTaskName))
157 if s.CancelWhenTimeout {
158 return buserr.New(i18n.GetWithName("TaskTimeout", subTaskName))
159 }
160 case err = <-done:
161 if err != nil {
162 s.RootTask.Log(i18n.GetWithNameAndErr("SubTaskFailed", subTaskName, err))
163 } else {
164 s.RootTask.Log(i18n.GetWithName("SubTaskSuccess", subTaskName))
165 return nil
166 }
167 }
168
169 if i == s.Retry {
170 if s.Rollback != nil {
171 s.Rollback(s.RootTask)
172 }
173 }
174 time.Sleep(1 * time.Second)
175 }
176 return err
177}
178
179func (t *Task) updateTask(task *model.Task) {
180 _ = t.taskRepo.Update(context.Background(), task)

Callers

nothing calls this directly

Calls 3

RollbackMethod · 0.65
LogStartMethod · 0.45
LogMethod · 0.45

Tested by

no test coverage detected