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

Function ReNewTask

agent/app/task/task.go:180–206  ·  view source on GitHub ↗
(name, operate, taskScope, taskID string, resourceID uint)

Source from the content-addressed store, hash-verified

178 return ReNewTask(GetTaskName(resourceName, operate, scope), operate, scope, taskID, resourceID)
179}
180func ReNewTask(name, operate, taskScope, taskID string, resourceID uint) (*Task, error) {
181 taskRepo := repo.NewITaskRepo()
182 taskItem, _ := taskRepo.GetFirst(taskRepo.WithByID(taskID))
183 if taskItem.ID == "" {
184 return NewTask(name, operate, taskScope, taskID, resourceID)
185 }
186 logDir := path.Join(global.Dir.TaskDir, taskScope)
187 if _, err := os.Stat(logDir); err != nil {
188 if err = os.MkdirAll(logDir, constant.DirPerm); err != nil {
189 return nil, fmt.Errorf("failed to create log directory: %w", err)
190 }
191 }
192
193 logPath := path.Join(global.Dir.TaskDir, taskScope, taskID+".log")
194 logger := logrus.New()
195 logger.SetFormatter(&SimpleFormatter{})
196 logFile, err := os.OpenFile(logPath, os.O_APPEND|os.O_CREATE|os.O_WRONLY, constant.FilePerm)
197 if err != nil {
198 return nil, fmt.Errorf("failed to open log file: %w", err)
199 }
200 logger.SetOutput(logFile)
201 logger.Print("\n --------------------------------------------------- \n")
202 taskItem.Status = constant.StatusExecuting
203 task := &Task{Name: name, logFile: logFile, Logger: logger, taskRepo: taskRepo, Task: &taskItem}
204 task.updateTask(&taskItem)
205 return task, nil
206}
207
208func (t *Task) AddSubTask(name string, action ActionFunc, rollback RollbackFunc) {
209 subTask := &SubTask{RootTask: t, Name: name, Retry: 0, Timeout: 30 * time.Minute, Action: action, Rollback: rollback}

Callers 1

ReNewTaskWithOpsFunction · 0.85

Calls 7

GetFirstMethod · 0.95
WithByIDMethod · 0.95
updateTaskMethod · 0.95
MkdirAllMethod · 0.80
OpenFileMethod · 0.80
NewTaskFunction · 0.70
StatMethod · 0.45

Tested by

no test coverage detected