Пример #1
0
// Print prints a list of tasks.
func Print(tasks []*api.Task, all bool, res *common.Resolver) {
	w := tabwriter.NewWriter(os.Stdout, 4, 4, 4, ' ', 0)
	defer w.Flush()

	common.PrintHeader(w, "Task ID", "Service", "Slot", "Image", "Desired State", "Last State", "Node")
	sort.Stable(tasksBySlot(tasks))
	for _, t := range tasks {
		if !all && t.DesiredState > api.TaskStateRunning {
			continue
		}
		c := t.Spec.GetContainer()
		fmt.Fprintf(w, "%s\t%s\t%d\t%s\t%s\t%s %s\t%s\n",
			t.ID,
			t.ServiceAnnotations.Name,
			t.Slot,
			c.Image,
			t.DesiredState.String(),
			t.Status.State.String(),
			common.TimestampAgo(t.Status.Timestamp),
			res.Resolve(api.Node{}, t.NodeID),
		)
	}
}
Пример #2
0
			if !quiet {
				w := tabwriter.NewWriter(os.Stdout, 0, 4, 2, ' ', 0)
				defer func() {
					// Ignore flushing errors - there's nothing we can do.
					_ = w.Flush()
				}()
				common.PrintHeader(w, "ID", "Service", "Desired State", "Last State", "Node")
				output = func(t *api.Task) {
					fmt.Fprintf(w, "%s\t%s.%d\t%s\t%s %s\t%s\n",
						t.ID,
						res.Resolve(api.Service{}, t.ServiceID),
						t.Slot,
						t.DesiredState.String(),
						t.Status.State.String(),
						common.TimestampAgo(t.Status.Timestamp),
						res.Resolve(api.Node{}, t.NodeID),
					)
				}
			} else {
				output = func(t *api.Task) { fmt.Println(t.ID) }
			}

			for _, t := range r.Tasks {
				if all || t.DesiredState <= api.TaskStateRunning {
					output(t)
				}
			}
			return nil
		},
	}