// Processes new tasks func (m *etcdMinion) processTask(t *task.Task) error { var buf bytes.Buffer // Update state of task to indicate that we are now processing it t.State = task.TaskStateProcessing m.SaveTaskResult(t) cmd := exec.Command(t.Command, t.Args...) cmd.Stdout = &buf cmd.Stderr = &buf log.Printf("Processing task %s\n", t.TaskID) cmdError := cmd.Run() t.TimeProcessed = time.Now().Unix() t.Result = buf.String() if cmdError != nil { log.Printf("Failed to process task %s\n", t.TaskID) t.Error = cmdError.Error() t.State = task.TaskStateFailed } else { log.Printf("Finished processing task %s\n", t.TaskID) t.State = task.TaskStateSuccess } m.SaveTaskResult(t) return cmdError }
// Processes new tasks func (m *etcdMinion) processTask(t *task.Task) error { defer func() { t.TimeProcessed = time.Now().Unix() m.SaveTaskResult(t) }() // Sync the module and data files, then process the task err := m.Sync() if err != nil { msg := fmt.Sprintf("Unable to sync site directory: %s\n", err) log.Printf(msg) t.State = task.TaskStateSkipped t.Result = msg return err } // Switch to the specified environment if err := m.setEnvironment(t.Environment); err != nil { msg := fmt.Sprintf("Unable to set environment: %s\n", err) log.Printf(msg) t.State = task.TaskStateSkipped t.Result = msg return err } t.State = task.TaskStateProcessing m.SaveTaskResult(t) // Create the catalog and process it var buf bytes.Buffer L := lua.NewState() defer L.Close() config := &catalog.Config{ Module: t.Command, DryRun: t.DryRun, Logger: log.New(&buf, "", log.LstdFlags), SiteRepo: m.gitRepo.Path, L: L, Concurrency: m.config.Concurrency, } katalog := catalog.New(config) if err := katalog.Load(); err != nil { t.State = task.TaskStateUnknown t.Result = err.Error() return err } status := katalog.Run() status.Summary(config.Logger) t.Result = buf.String() t.State = task.TaskStateSuccess return nil }