From 73c38a143613f48d2c97b2c1886ad1afb224082a Mon Sep 17 00:00:00 2001 From: ben dewan Date: Tue, 1 Aug 2017 10:55:23 -0400 Subject: [PATCH] Make the recipe polling interval user-configurable --- cmd/provision.go | 7 ++++++- connection/connection.go | 9 +++++++-- connection/connection_internal.go | 2 +- 3 files changed, 14 insertions(+), 4 deletions(-) diff --git a/cmd/provision.go b/cmd/provision.go index f856fb2..2afe948 100644 --- a/cmd/provision.go +++ b/cmd/provision.go @@ -52,7 +52,8 @@ func doProvision(cmd *cobra.Command, args []string) { log.Fatal(err) } - cxn, err := connection.Init(viper.GetString("api-key"), verbose) + cxn, err := connection.Init(viper.GetString("api-key"), + viper.GetInt("polling-interval"), verbose) if err != nil { log.Fatal(err) } @@ -87,8 +88,12 @@ func init() { process deployments to the specified cluster`) provisionCmd.Flags().StringP("output", "o", "./connection-strings.yml", `The file to write connection string information to.`) + provisionCmd.Flags().IntP("polling-interval", "p", 5, + `The polling interval, in seconds, to use when + waiting for a provisioning recipe to complete`) viper.BindPFlag("fail-fast", provisionCmd.Flags().Lookup("fail-fast")) viper.BindPFlag("cluster", provisionCmd.Flags().Lookup("cluster")) viper.BindPFlag("output", provisionCmd.Flags().Lookup("output")) + viper.BindPFlag("polling-interval", provisionCmd.Flags().Lookup("polling-interval")) } diff --git a/connection/connection.go b/connection/connection.go index be4c7fc..d58de24 100644 --- a/connection/connection.go +++ b/connection/connection.go @@ -24,6 +24,7 @@ import ( "bytes" "fmt" "os" + "time" compose "github.com/compose/gocomposeapi" "github.com/ghodss/yaml" @@ -47,10 +48,14 @@ type Connection struct { clusterIDsByName map[string]string deploymentsByName map[string](*compose.Deployment) newDeploymentIDs []string + pollingInterval time.Duration } -func Init(apiKey string, verbose bool) (*Connection, error) { - cxn := &Connection{newDeploymentIDs: []string{}} +func Init(apiKey string, pollingInterval int, verbose bool) (*Connection, error) { + cxn := &Connection{ + newDeploymentIDs: []string{}, + pollingInterval: time.Duration(pollingInterval) * time.Second, + } var err error cxn.client, err = createClient(apiKey) diff --git a/connection/connection_internal.go b/connection/connection_internal.go index 4e4be90..325d30a 100644 --- a/connection/connection_internal.go +++ b/connection/connection_internal.go @@ -108,7 +108,7 @@ func (cxn *Connection) waitOnRecipe(recipeID string, timeout float64, verbose bo if recipe.Status == "complete" { return nil } - time.Sleep(5 * time.Second) + time.Sleep(cxn.pollingInterval) } return fmt.Errorf("Timed out waiting on recipe %v to complete", recipeID) }