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

Method Execute

agent/app/task/task.go:233–279  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

231}
232
233func (s *SubTask) Execute() error {
234 defer delete(global.TaskCtxMap, s.RootTask.TaskID)
235 subTaskName := s.Name
236 if s.Name == "" {
237 subTaskName = i18n.GetMsgByKey("SubTask")
238 }
239 var err error
240 for i := 0; i < s.Retry+1; i++ {
241 if i > 0 {
242 s.RootTask.Log(i18n.GetWithName("TaskRetry", strconv.Itoa(i)))
243 }
244 ctx, cancel := context.WithTimeout(context.Background(), s.Timeout)
245 if s.Timeout == 0 {
246 ctx, cancel = context.WithCancel(context.Background())
247 }
248 defer cancel()
249
250 done := make(chan error)
251 go func() {
252 done <- s.Action(s.RootTask)
253 }()
254
255 select {
256 case <-ctx.Done():
257 s.RootTask.Log(i18n.GetWithName("TaskTimeout", subTaskName))
258 err = errors.New("timeout!")
259 case err = <-done:
260 if err != nil {
261 s.RootTask.Log(i18n.GetWithNameAndErr("SubTaskFailed", subTaskName, err))
262 if err.Error() == i18n.GetMsgByKey("ErrShutDown") {
263 return err
264 }
265 } else {
266 s.RootTask.Log(i18n.GetWithName("SubTaskSuccess", subTaskName))
267 return nil
268 }
269 }
270
271 if i == s.Retry {
272 if s.Rollback != nil {
273 s.Rollback(s.RootTask)
274 }
275 }
276 time.Sleep(1 * time.Second)
277 }
278 return err
279}
280
281func (t *Task) updateTask(task *model.Task) {
282 _ = t.taskRepo.Update(context.Background(), task)

Callers

nothing calls this directly

Calls 3

RollbackMethod · 0.65
LogMethod · 0.45
ErrorMethod · 0.45

Tested by

no test coverage detected