From 812fb60805c7f4b98d0641247dc02ddcc7ab8c7a Mon Sep 17 00:00:00 2001 From: Brian DeHamer Date: Wed, 29 Jul 2015 20:03:47 +0000 Subject: [PATCH] Handle errors without halting If we receive an error while trying to shutdown/startup a particular container we don't want to immediately terminate the current update cycle. Instead we should continue processing the remaining containers and simply log the error. --- actions/update.go | 13 ++++++++----- container/client.go | 4 ++-- 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/actions/update.go b/actions/update.go index ce3f331..d997832 100644 --- a/actions/update.go +++ b/actions/update.go @@ -2,13 +2,15 @@ package actions import ( "math/rand" + "time" "github.com/CenturyLinkLabs/watchtower/container" log "github.com/Sirupsen/logrus" ) var ( - letters = []rune("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ") + letters = []rune("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ") + waitTime = 10 * time.Second ) func allContainersFilter(container.Container) bool { return true } @@ -45,8 +47,8 @@ func Update(client container.Client) error { } if container.Stale { - if err := client.StopContainer(container, 10); err != nil { - return err + if err := client.StopContainer(container, waitTime); err != nil { + log.Error(err) } } } @@ -60,12 +62,13 @@ func Update(client container.Client) error { // instance so that the new one can adopt the old name. if container.IsWatchtower() { if err := client.RenameContainer(container, randName()); err != nil { - return err + log.Error(err) + continue } } if err := client.StartContainer(container); err != nil { - return err + log.Error(err) } } } diff --git a/container/client.go b/container/client.go index 0c69316..9e2af12 100644 --- a/container/client.go +++ b/container/client.go @@ -160,8 +160,8 @@ func (client DockerClient) waitForStop(c Container, waitTime time.Duration) erro } else if !ci.State.Running { return nil } - - time.Sleep(1 * time.Second) } + + time.Sleep(1 * time.Second) } }