cli: `wait` flag for use with `deployment status -monitor` (#15262)
This commit is contained in:
parent
918a91f8bf
commit
62f7de7ed5
|
@ -0,0 +1,3 @@
|
|||
```release-note:improvement
|
||||
cli: Added `-wait` flag to `deployment status` for use with `-monitor` mode
|
||||
```
|
|
@ -48,6 +48,10 @@ Status Options:
|
|||
-monitor
|
||||
Enter monitor mode to poll for updates to the deployment status.
|
||||
|
||||
-wait
|
||||
How long to wait before polling an update, used in conjunction with monitor
|
||||
mode. Defaults to 2s.
|
||||
|
||||
-t
|
||||
Format and display deployment using a Go template.
|
||||
`
|
||||
|
@ -87,6 +91,7 @@ func (c *DeploymentStatusCommand) Name() string { return "deployment status" }
|
|||
|
||||
func (c *DeploymentStatusCommand) Run(args []string) int {
|
||||
var json, verbose, monitor bool
|
||||
var wait time.Duration
|
||||
var tmpl string
|
||||
|
||||
flags := c.Meta.FlagSet(c.Name(), FlagSetClient)
|
||||
|
@ -95,6 +100,7 @@ func (c *DeploymentStatusCommand) Run(args []string) int {
|
|||
flags.BoolVar(&json, "json", false, "")
|
||||
flags.BoolVar(&monitor, "monitor", false, "")
|
||||
flags.StringVar(&tmpl, "t", "", "")
|
||||
flags.DurationVar(&wait, "wait", 2*time.Second, "")
|
||||
|
||||
if err := flags.Parse(args); err != nil {
|
||||
return 1
|
||||
|
@ -172,7 +178,7 @@ func (c *DeploymentStatusCommand) Run(args []string) int {
|
|||
|
||||
c.Ui.Output(fmt.Sprintf("%s: Monitoring deployment %q",
|
||||
formatTime(time.Now()), limit(deploy.ID, length)))
|
||||
c.monitor(client, deploy.ID, meta.LastIndex, verbose)
|
||||
c.monitor(client, deploy.ID, meta.LastIndex, wait, verbose)
|
||||
|
||||
return 0
|
||||
}
|
||||
|
@ -180,11 +186,11 @@ func (c *DeploymentStatusCommand) Run(args []string) int {
|
|||
return 0
|
||||
}
|
||||
|
||||
func (c *DeploymentStatusCommand) monitor(client *api.Client, deployID string, index uint64, verbose bool) (status string, err error) {
|
||||
func (c *DeploymentStatusCommand) monitor(client *api.Client, deployID string, index uint64, wait time.Duration, verbose bool) (status string, err error) {
|
||||
if isStdoutTerminal() {
|
||||
return c.ttyMonitor(client, deployID, index, verbose)
|
||||
return c.ttyMonitor(client, deployID, index, wait, verbose)
|
||||
} else {
|
||||
return c.defaultMonitor(client, deployID, index, verbose)
|
||||
return c.defaultMonitor(client, deployID, index, wait, verbose)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -207,7 +213,7 @@ func isStdoutTerminal() bool {
|
|||
// but only used for tty and non-Windows machines since glint doesn't work with
|
||||
// cmd/PowerShell and non-interactive interfaces
|
||||
// Margins are used to match the text alignment from job run
|
||||
func (c *DeploymentStatusCommand) ttyMonitor(client *api.Client, deployID string, index uint64, verbose bool) (status string, err error) {
|
||||
func (c *DeploymentStatusCommand) ttyMonitor(client *api.Client, deployID string, index uint64, wait time.Duration, verbose bool) (status string, err error) {
|
||||
var length int
|
||||
if verbose {
|
||||
length = fullId
|
||||
|
@ -233,7 +239,7 @@ func (c *DeploymentStatusCommand) ttyMonitor(client *api.Client, deployID string
|
|||
q := api.QueryOptions{
|
||||
AllowStale: true,
|
||||
WaitIndex: index,
|
||||
WaitTime: 2 * time.Second,
|
||||
WaitTime: wait,
|
||||
}
|
||||
|
||||
var statusComponent *glint.LayoutComponent
|
||||
|
@ -331,7 +337,7 @@ UPDATE:
|
|||
}
|
||||
|
||||
d.Close()
|
||||
c.ttyMonitor(client, rollback.ID, index, verbose)
|
||||
c.ttyMonitor(client, rollback.ID, index, wait, verbose)
|
||||
return
|
||||
} else {
|
||||
endSpinner = glint.Layout(
|
||||
|
@ -361,7 +367,7 @@ UPDATE:
|
|||
}
|
||||
|
||||
// Used for Windows and non-tty
|
||||
func (c *DeploymentStatusCommand) defaultMonitor(client *api.Client, deployID string, index uint64, verbose bool) (status string, err error) {
|
||||
func (c *DeploymentStatusCommand) defaultMonitor(client *api.Client, deployID string, index uint64, wait time.Duration, verbose bool) (status string, err error) {
|
||||
writer := uilive.New()
|
||||
writer.Start()
|
||||
defer writer.Stop()
|
||||
|
@ -376,7 +382,7 @@ func (c *DeploymentStatusCommand) defaultMonitor(client *api.Client, deployID st
|
|||
q := api.QueryOptions{
|
||||
AllowStale: true,
|
||||
WaitIndex: index,
|
||||
WaitTime: 2 * time.Second,
|
||||
WaitTime: wait,
|
||||
}
|
||||
|
||||
for {
|
||||
|
@ -438,7 +444,7 @@ func (c *DeploymentStatusCommand) defaultMonitor(client *api.Client, deployID st
|
|||
if rollback.ID == deploy.ID {
|
||||
return
|
||||
}
|
||||
c.defaultMonitor(client, rollback.ID, index, verbose)
|
||||
c.defaultMonitor(client, rollback.ID, index, wait, verbose)
|
||||
}
|
||||
return
|
||||
|
||||
|
|
|
@ -299,7 +299,7 @@ func (m *monitor) monitor(evalID string) int {
|
|||
meta := new(Meta)
|
||||
meta.Ui = m.ui
|
||||
cmd := &DeploymentStatusCommand{Meta: *meta}
|
||||
status, err := cmd.monitor(m.client, dID, 0, verbose)
|
||||
status, err := cmd.monitor(m.client, dID, 0, m.state.wait, verbose)
|
||||
if err != nil || status != api.DeploymentStatusSuccessful {
|
||||
return 1
|
||||
}
|
||||
|
|
|
@ -20,8 +20,8 @@ nomad deployment status [options] <deployment id>
|
|||
The `deployment status` command requires a single argument, a deployment ID or
|
||||
prefix.
|
||||
|
||||
A `-monitor` flag can be used to update the current deployment status until completion.
|
||||
When combined with `-verbose`, it will also display the allocations for the given
|
||||
A `-monitor` flag can be used to update the current deployment status until completion.
|
||||
When combined with `-verbose`, it will also display the allocations for the given
|
||||
deployment. If the deployment fails and [`auto_revert`] is set to `true`, it will monitor
|
||||
the entire process, showing the failure and then monitoring the deployment of the rollback.
|
||||
|
||||
|
@ -38,6 +38,8 @@ capability for the deployment's namespace.
|
|||
- `-t` : Format and display the deployment using a Go template.
|
||||
- `-verbose`: Show full information.
|
||||
- `-monitor`: Enter monitor mode to poll for updates to the deployment status.
|
||||
- `-wait`: How long to wait before polling an update, used in conjunction with monitor
|
||||
mode. Defaults to 2s.
|
||||
|
||||
## Examples
|
||||
|
||||
|
|
Loading…
Reference in New Issue