Skip to content

Commit

Permalink
Make the recipe polling interval user-configurable
Browse files Browse the repository at this point in the history
  • Loading branch information
ben dewan committed Aug 1, 2017
1 parent 53261c0 commit 73c38a1
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 4 deletions.
7 changes: 6 additions & 1 deletion cmd/provision.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down Expand Up @@ -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"))
}
9 changes: 7 additions & 2 deletions connection/connection.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import (
"bytes"
"fmt"
"os"
"time"

compose "github.com/compose/gocomposeapi"
"github.com/ghodss/yaml"
Expand All @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion connection/connection_internal.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down

0 comments on commit 73c38a1

Please sign in to comment.