mirror of
https://github.com/kemko/nomad.git
synced 2026-01-06 18:35:44 +03:00
command: easier exit codes, check if eval is already finished
This commit is contained in:
@@ -22,9 +22,8 @@ Usage: nomad eval-monitor [options] <evaluation>
|
||||
real-time to the terminal.
|
||||
|
||||
The command will exit when the given evaluation reaches a terminal
|
||||
state (completed or failed). The exit status will reflect the
|
||||
result of the evaluation (0 on success, 1 on failure). Exit code
|
||||
1 may also be encountered for client connectivity errors.
|
||||
state (completed or failed). The exit code indicates the status
|
||||
of the monitoring only; it does not reflect the evaluation status.
|
||||
|
||||
General Options:
|
||||
|
||||
|
||||
@@ -129,10 +129,23 @@ func (m *monitor) update(eval *api.Evaluation, allocs []*api.AllocationListStub)
|
||||
|
||||
// monitor is used to start monitoring the given evaluation ID. It
|
||||
// writes output directly to the monitor's ui, and returns the
|
||||
// exit code for the command. The return code is 0 if monitoring
|
||||
// succeeded and exited successfully, or 1 if an error was encountered
|
||||
// or the eval status was returned as failed.
|
||||
// exit code for the command. The return code indicates monitoring
|
||||
// success or failure ONLY. It is no indication of the outcome of
|
||||
// the evaluation, since conflating these values obscures things.
|
||||
func (m *monitor) monitor(evalID string) int {
|
||||
// Check if the eval has already completed and fast-path it.
|
||||
eval, _, err := m.client.Evaluations().Info(evalID, nil)
|
||||
if err != nil {
|
||||
m.ui.Error(fmt.Sprintf("Error reading evaluation: %s", err))
|
||||
return 1
|
||||
}
|
||||
switch eval.Status {
|
||||
case structs.EvalStatusComplete, structs.EvalStatusFailed:
|
||||
m.ui.Info(fmt.Sprintf("Evaluation %q already finished with status %q",
|
||||
evalID, eval.Status))
|
||||
return 0
|
||||
}
|
||||
|
||||
m.ui.Info(fmt.Sprintf("Monitoring evaluation %q", evalID))
|
||||
for {
|
||||
// Check the current state of things
|
||||
@@ -165,14 +178,7 @@ func (m *monitor) monitor(evalID string) int {
|
||||
if eval.NextEval != "" {
|
||||
return m.monitor(eval.NextEval)
|
||||
}
|
||||
|
||||
// Check if the eval is complete
|
||||
switch eval.Status {
|
||||
case structs.EvalStatusComplete:
|
||||
return 0
|
||||
case structs.EvalStatusFailed:
|
||||
return 1
|
||||
}
|
||||
break
|
||||
}
|
||||
|
||||
return 0
|
||||
|
||||
Reference in New Issue
Block a user