mirror of
https://github.com/offen/docker-volume-backup.git
synced 2024-11-23 05:30:33 +01:00
Time out after five minutes of not reaching desired container count
This commit is contained in:
parent
26bbc66cd5
commit
2bc94d8a5b
@ -42,7 +42,20 @@ func scaleService(cli *client.Client, serviceID string, replicas uint64) ([]stri
|
|||||||
}
|
}
|
||||||
|
|
||||||
func awaitContainerCountForService(cli *client.Client, serviceID string, count int) error {
|
func awaitContainerCountForService(cli *client.Client, serviceID string, count int) error {
|
||||||
|
poll := time.NewTicker(time.Second)
|
||||||
|
timeout := time.NewTicker(5 * time.Minute)
|
||||||
|
defer timeout.Stop()
|
||||||
|
defer poll.Stop()
|
||||||
|
|
||||||
for {
|
for {
|
||||||
|
select {
|
||||||
|
case <-timeout.C:
|
||||||
|
return fmt.Errorf(
|
||||||
|
"awaitContainerCount: timed out after waiting 5 minutes for service %s to reach desired container count of %d",
|
||||||
|
serviceID,
|
||||||
|
count,
|
||||||
|
)
|
||||||
|
case <-poll.C:
|
||||||
containers, err := cli.ContainerList(context.Background(), types.ContainerListOptions{
|
containers, err := cli.ContainerList(context.Background(), types.ContainerListOptions{
|
||||||
Filters: filters.NewArgs(filters.KeyValuePair{
|
Filters: filters.NewArgs(filters.KeyValuePair{
|
||||||
Key: "label",
|
Key: "label",
|
||||||
@ -53,11 +66,10 @@ func awaitContainerCountForService(cli *client.Client, serviceID string, count i
|
|||||||
return fmt.Errorf("awaitContainerCount: error listing containers: %w", err)
|
return fmt.Errorf("awaitContainerCount: error listing containers: %w", err)
|
||||||
}
|
}
|
||||||
if len(containers) == count {
|
if len(containers) == count {
|
||||||
break
|
|
||||||
}
|
|
||||||
time.Sleep(time.Second)
|
|
||||||
}
|
|
||||||
return nil
|
return nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// stopContainersAndServices stops all Docker containers that are marked as to being
|
// stopContainersAndServices stops all Docker containers that are marked as to being
|
||||||
|
Loading…
Reference in New Issue
Block a user