From 94a660147e5e2e9a1350cbdda7397d85cd30af17 Mon Sep 17 00:00:00 2001 From: Megan Marsh Date: Mon, 16 Nov 2020 11:49:33 -0800 Subject: [PATCH] rename retry so it doesn't stutter --- builder/osc/common/retry/retry.go | 4 ++-- builder/osc/common/retry/retry_test.go | 8 ++++---- builder/osc/common/state.go | 2 +- builder/osc/common/step_create_tags.go | 2 +- builder/osc/common/step_run_source_vm.go | 2 +- builder/osc/common/step_stop_bsu_backed_vm.go | 2 +- 6 files changed, 10 insertions(+), 10 deletions(-) diff --git a/builder/osc/common/retry/retry.go b/builder/osc/common/retry/retry.go index 628a86a69..531000335 100644 --- a/builder/osc/common/retry/retry.go +++ b/builder/osc/common/retry/retry.go @@ -15,7 +15,7 @@ var RetryExhaustedError error = fmt.Errorf("Function never succeeded in Retry") type RetryableFunc func(uint) (bool, error) /* -Retry retries a function up to numTries times with exponential backoff. +Run retries a function up to numTries times with exponential backoff. If numTries == 0, retry indefinitely. If interval == 0, Retry will not delay retrying and there will be no exponential backoff. @@ -24,7 +24,7 @@ Intervals are in seconds. Returns an error if initial > max intervals, if retries are exhausted, or if the passed function returns an error. */ -func Retry(initialInterval float64, maxInterval float64, numTries uint, function RetryableFunc) error { +func Run(initialInterval float64, maxInterval float64, numTries uint, function RetryableFunc) error { if maxInterval == 0 { maxInterval = math.Inf(1) } else if initialInterval < 0 || initialInterval > maxInterval { diff --git a/builder/osc/common/retry/retry_test.go b/builder/osc/common/retry/retry_test.go index bd59cb459..9936b2652 100644 --- a/builder/osc/common/retry/retry_test.go +++ b/builder/osc/common/retry/retry_test.go @@ -8,7 +8,7 @@ import ( func TestRetry(t *testing.T) { numTries := uint(0) // Test that a passing function only gets called once. - err := Retry(0, 0, 0, func(i uint) (bool, error) { + err := Run(0, 0, 0, func(i uint) (bool, error) { numTries++ return true, nil }) @@ -22,7 +22,7 @@ func TestRetry(t *testing.T) { // Test that a failing function gets retried (once in this example). numTries = 0 results := []bool{false, true} - err = Retry(0, 0, 0, func(i uint) (bool, error) { + err = Run(0, 0, 0, func(i uint) (bool, error) { result := results[numTries] numTries++ return result, nil @@ -37,7 +37,7 @@ func TestRetry(t *testing.T) { // Test that a function error gets returned, and the function does not get called again. numTries = 0 funcErr := fmt.Errorf("This function had an error!") - err = Retry(0, 0, 0, func(i uint) (bool, error) { + err = Run(0, 0, 0, func(i uint) (bool, error) { numTries++ return false, funcErr }) @@ -51,7 +51,7 @@ func TestRetry(t *testing.T) { // Test when a function exhausts its retries. numTries = 0 expectedTries := uint(3) - err = Retry(0, 0, expectedTries, func(i uint) (bool, error) { + err = Run(0, 0, expectedTries, func(i uint) (bool, error) { numTries++ return false, nil }) diff --git a/builder/osc/common/state.go b/builder/osc/common/state.go index 50afe4cce..302df6d24 100644 --- a/builder/osc/common/state.go +++ b/builder/osc/common/state.go @@ -68,7 +68,7 @@ func WaitUntilOscSnapshotDone(conn *osc.APIClient, snapshotID string) error { } func waitForState(errCh chan<- error, target string, refresh stateRefreshFunc) { - err := retry.Retry(2, 2, 0, func(_ uint) (bool, error) { + err := retry.Run(2, 2, 0, func(_ uint) (bool, error) { state, err := refresh() if err != nil { return false, err diff --git a/builder/osc/common/step_create_tags.go b/builder/osc/common/step_create_tags.go index 2a2c60961..49f784de8 100644 --- a/builder/osc/common/step_create_tags.go +++ b/builder/osc/common/step_create_tags.go @@ -90,7 +90,7 @@ func (s *StepCreateTags) Run(_ context.Context, state multistep.StateBag) multis snapshotTags.Report(ui) // Retry creating tags for about 2.5 minutes - err = retry.Retry(0.2, 30, 11, func(_ uint) (bool, error) { + err = retry.Run(0.2, 30, 11, func(_ uint) (bool, error) { // Tag images and snapshots _, _, err := regionconn.TagApi.CreateTags(context.Background(), &osc.CreateTagsOpts{ CreateTagsRequest: optional.NewInterface(osc.CreateTagsRequest{ diff --git a/builder/osc/common/step_run_source_vm.go b/builder/osc/common/step_run_source_vm.go index 0d0cb6054..d5ba558c6 100644 --- a/builder/osc/common/step_run_source_vm.go +++ b/builder/osc/common/step_run_source_vm.go @@ -234,7 +234,7 @@ func (s *StepRunSourceVm) Run(ctx context.Context, state multistep.StateBag) mul if s.IsRestricted { oscTags.Report(ui) // Retry creating tags for about 2.5 minutes - err = retry.Retry(0.2, 30, 11, func(_ uint) (bool, error) { + err = retry.Run(0.2, 30, 11, func(_ uint) (bool, error) { _, _, err := oscconn.TagApi.CreateTags(context.Background(), &osc.CreateTagsOpts{ CreateTagsRequest: optional.NewInterface(osc.CreateTagsRequest{ Tags: oscTags, diff --git a/builder/osc/common/step_stop_bsu_backed_vm.go b/builder/osc/common/step_stop_bsu_backed_vm.go index 62cd830ac..11dd2654c 100644 --- a/builder/osc/common/step_stop_bsu_backed_vm.go +++ b/builder/osc/common/step_stop_bsu_backed_vm.go @@ -41,7 +41,7 @@ func (s *StepStopBSUBackedVm) Run(ctx context.Context, state multistep.StateBag) // does not exist. // Work around this by retrying a few times, up to about 5 minutes. - err := retry.Retry(10, 60, 6, func(i uint) (bool, error) { + err := retry.Run(10, 60, 6, func(i uint) (bool, error) { ui.Message(fmt.Sprintf("Stopping vm, attempt %d", i+1)) _, _, err = oscconn.VmApi.StopVms(context.Background(), &osc.StopVmsOpts{