func TestMinionTaskBacklog(t *testing.T) { tc := mustNewTestClient("fixtures/minion-task-backlog") defer tc.recorder.Stop() // Setup our minion minionName := "Kevin" cfg := &minion.EtcdMinionConfig{ Name: minionName, EtcdConfig: tc.config, } testMinion, err := minion.NewEtcdMinion(cfg) if err != nil { t.Fatal(err) } minionID := testMinion.ID() err = testMinion.SetName(minionName) if err != nil { t.Fatal(err) } // Create a test task and submit it wantTask := task.New("foo", "bar") wantTask.ID = uuid.Parse("e6d2bebd-2219-4a8c-9d30-a861097c147e") err = tc.client.MinionSubmitTask(minionID, wantTask) if err != nil { t.Fatal(err) } // Get pending tasks and verify the task we sent is the task we get backlog, err := tc.client.MinionTaskQueue(minionID) if err != nil { t.Fatal(err) } if len(backlog) != 1 { t.Errorf("want 1 backlog task, got %d backlog tasks", len(backlog)) } gotTask := backlog[0] if !reflect.DeepEqual(wantTask, gotTask) { t.Errorf("want %q task, got %q task", wantTask.ID, gotTask.ID) } }
// Executes the "run" command func execRunCommand(c *cli.Context) { if len(c.Args()) < 1 { displayError(errMissingTask, 64) } client := newEtcdMinionClientFromFlags(c) cFlag := c.String("with-classifier") minions, err := parseClassifierPattern(client, cFlag) if err != nil { displayError(err, 1) } numMinions := len(minions) if numMinions == 0 { displayError(errNoMinionFound, 1) } fmt.Printf("Found %d minion(s) for task processing\n\n", numMinions) // Create the task that we send to our minions // The first argument is the command and anything else // that follows is considered task arguments args := c.Args() isConcurrent := c.Bool("is-concurrent") taskCommand := args[0] taskArgs := args[1:] t := task.New(taskCommand, taskArgs...) t.IsConcurrent = isConcurrent // Progress bar to display while submitting task progress := uiprogress.New() bar := progress.AddBar(numMinions) bar.AppendCompleted() bar.PrependElapsed() progress.Start() // Number of minions to which submitting the task has failed failed := 0 // Submit task to minions fmt.Println("Submitting task to minion(s) ...") for _, minion := range minions { err = client.MinionSubmitTask(minion, t) if err != nil { fmt.Printf("Failed to submit task to %s: %s\n", minion, err) failed += 1 } bar.Incr() } // Stop progress bar and sleep for a bit to make sure the // progress bar gets updated if we were too fast for it progress.Stop() time.Sleep(time.Millisecond * 100) // Display task report fmt.Println() table := uitable.New() table.MaxColWidth = 80 table.Wrap = true table.AddRow("TASK", "SUBMITTED", "FAILED", "TOTAL") table.AddRow(t.TaskID, numMinions-failed, failed, numMinions) fmt.Println(table) }
// Executes the "push" command func execPushCommand(c *cli.Context) error { if len(c.Args()) < 1 { return cli.NewExitError(errNoModuleName.Error(), 64) } // Create the task that we send to our minions // The task's command is the module name that will be // loaded and processed by the remote minions main := c.Args()[0] t := task.New(main, c.String("environment")) client := newEtcdMinionClientFromFlags(c) cFlag := c.String("with-classifier") minions, err := parseClassifierPattern(client, cFlag) if err != nil { return cli.NewExitError(err.Error(), 1) } numMinions := len(minions) if numMinions == 0 { return cli.NewExitError(errNoMinionFound.Error(), 1) } fmt.Printf("Found %d minion(s) for task processing\n\n", numMinions) // Progress bar to display while submitting task progress := uiprogress.New() bar := progress.AddBar(numMinions) bar.AppendCompleted() bar.PrependElapsed() progress.Start() // Number of minions to which submitting the task has failed failed := 0 // Submit task to minions fmt.Println("Submitting task to minion(s) ...") for _, m := range minions { err = client.MinionSubmitTask(m, t) if err != nil { fmt.Printf("Failed to submit task to %s: %s\n", m, err) failed++ } bar.Incr() } // Stop progress bar and sleep for a bit to make sure the // progress bar gets updated if we were too fast for it progress.Stop() time.Sleep(time.Millisecond * 100) // Display task report fmt.Println() table := uitable.New() table.MaxColWidth = 80 table.Wrap = true table.AddRow("TASK", "SUBMITTED", "FAILED", "TOTAL") table.AddRow(t.ID, numMinions-failed, failed, numMinions) fmt.Println(table) return nil }