Skip to content
This repository has been archived by the owner on Nov 1, 2022. It is now read-only.

Commit

Permalink
Make --timeout flag of type duration
Browse files Browse the repository at this point in the history
  • Loading branch information
hiddeco committed Jul 11, 2019
1 parent 0458c55 commit a839529
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 9 deletions.
10 changes: 5 additions & 5 deletions cmd/fluxctl/await.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ var ErrTimeout = errors.New("timeout")

// await polls for a job to complete, then for the resulting commit to
// be applied
func await(ctx context.Context, stdout, stderr io.Writer, client api.Server, jobID job.ID, apply bool, verbosity int, timeout int) error {
func await(ctx context.Context, stdout, stderr io.Writer, client api.Server, jobID job.ID, apply bool, verbosity int, timeout time.Duration) error {
result, err := awaitJob(ctx, client, jobID, timeout)
if err != nil {
if err == ErrTimeout {
Expand Down Expand Up @@ -61,9 +61,9 @@ to run a sync interactively.`)
}

// await polls for a job to have been completed, with exponential backoff.
func awaitJob(ctx context.Context, client api.Server, jobID job.ID, timeout int) (job.Result, error) {
func awaitJob(ctx context.Context, client api.Server, jobID job.ID, timeout time.Duration) (job.Result, error) {
var result job.Result
err := backoff(100*time.Millisecond, 2, 50, time.Duration(timeout)*time.Second, func() (bool, error) {
err := backoff(100*time.Millisecond, 2, 50, timeout, func() (bool, error) {
j, err := client.JobStatus(ctx, jobID)
if err != nil {
return false, err
Expand All @@ -86,8 +86,8 @@ func awaitJob(ctx context.Context, client api.Server, jobID job.ID, timeout int)
}

// await polls for a commit to have been applied, with exponential backoff.
func awaitSync(ctx context.Context, client api.Server, revision string, timeout int) error {
return backoff(1*time.Second, 2, 10, time.Duration(timeout)*time.Second, func() (bool, error) {
func awaitSync(ctx context.Context, client api.Server, revision string, timeout time.Duration) error {
return backoff(1*time.Second, 2, 10, timeout, func() (bool, error) {
refs, err := client.SyncStatus(ctx, revision)
return err == nil && len(refs) == 0, err
})
Expand Down
8 changes: 4 additions & 4 deletions cmd/fluxctl/root_cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"net/url"
"os"
"strings"
"time"

"github.com/pkg/errors"
"github.com/spf13/cobra"
Expand All @@ -23,7 +24,7 @@ type rootOpts struct {
Namespace string
Labels map[string]string
API api.Server
Timeout int
Timeout time.Duration
}

func newRoot() *rootOpts {
Expand Down Expand Up @@ -77,9 +78,8 @@ func (opts *rootOpts) Command() *cobra.Command {
fmt.Sprintf("Base URL of the Flux API (defaults to %q if a token is provided); you can also set the environment variable %s", defaultURLGivenToken, envVariableURL))
cmd.PersistentFlags().StringVarP(&opts.Token, "token", "t", "",
fmt.Sprintf("Weave Cloud authentication token; you can also set the environment variable %s or %s", envVariableCloudToken, envVariableToken))
cmd.PersistentFlags().IntVar(&opts.Timeout, "timeout", 60,
fmt.Sprintf("Global command timeout, in seconds; you can also set the environment variable %s", envVariableTimeout))

cmd.PersistentFlags().DurationVar(&opts.Timeout, "timeout", 60*time.Second,
fmt.Sprintf("Global command timeout; you can also set the environment variable %s", envVariableTimeout))
cmd.AddCommand(
newVersionCommand(),
newImageList(opts).Command(),
Expand Down

0 comments on commit a839529

Please sign in to comment.