mirror of
https://github.com/containers/podman.git
synced 2025-05-20 00:27:03 +08:00
rework apiv2 wait endpoint|binding
added the ability to wait on a condition (stopped, running, paused...) for a container. if a condition is not provided, wait will default to the stopped condition which uses the original wait code paths. if the condition is stopped, the container exit code will be returned. also, correct a mux issue we discovered. Signed-off-by: Brent Baude <bbaude@redhat.com>
This commit is contained in:
@ -629,6 +629,26 @@ func (c *Container) WaitWithInterval(waitTimeout time.Duration) (int32, error) {
|
||||
}
|
||||
}
|
||||
|
||||
func (c *Container) WaitForConditionWithInterval(waitTimeout time.Duration, condition define.ContainerStatus) (int32, error) {
|
||||
if !c.valid {
|
||||
return -1, define.ErrCtrRemoved
|
||||
}
|
||||
if condition == define.ContainerStateStopped || condition == define.ContainerStateExited {
|
||||
return c.WaitWithInterval(waitTimeout)
|
||||
}
|
||||
for {
|
||||
state, err := c.State()
|
||||
if err != nil {
|
||||
return -1, err
|
||||
}
|
||||
if state == condition {
|
||||
break
|
||||
}
|
||||
time.Sleep(waitTimeout)
|
||||
}
|
||||
return -1, nil
|
||||
}
|
||||
|
||||
// Cleanup unmounts all mount points in container and cleans up container storage
|
||||
// It also cleans up the network stack
|
||||
func (c *Container) Cleanup(ctx context.Context) error {
|
||||
|
Reference in New Issue
Block a user