Skip to content

Commit

Permalink
Fix timeout issue with project services (#737)
Browse files Browse the repository at this point in the history
* retry api enablement/disablement for 10 minutes

* retry to retryTime
  • Loading branch information
danawillow authored Nov 14, 2017
1 parent 3bd6e35 commit 2c8dbac
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
8 changes: 4 additions & 4 deletions google/resource_google_project_services.go
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ func getApiServices(pid string, config *Config, ignore map[string]struct{}) ([]s

func enableService(s, pid string, config *Config) error {
esr := newEnableServiceRequest(pid)
err := retry(func() error {
err := retryTime(func() error {
sop, err := config.clientServiceMan.Services.Enable(s, esr).Do()
if err != nil {
return err
Expand All @@ -196,7 +196,7 @@ func enableService(s, pid string, config *Config) error {
return waitErr
}
return nil
})
}, 10)
if err != nil {
return fmt.Errorf("Error enabling service %q for project %q: %v", s, pid, err)
}
Expand All @@ -205,7 +205,7 @@ func enableService(s, pid string, config *Config) error {

func disableService(s, pid string, config *Config) error {
dsr := newDisableServiceRequest(pid)
err := retry(func() error {
err := retryTime(func() error {
sop, err := config.clientServiceMan.Services.Disable(s, dsr).Do()
if err != nil {
return err
Expand All @@ -216,7 +216,7 @@ func disableService(s, pid string, config *Config) error {
return waitErr
}
return nil
})
}, 10)
if err != nil {
return fmt.Errorf("Error disabling service %q for project %q: %v", s, pid, err)
}
Expand Down
6 changes: 5 additions & 1 deletion google/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -385,7 +385,11 @@ func mergeSchemas(a, b map[string]*schema.Schema) map[string]*schema.Schema {
}

func retry(retryFunc func() error) error {
return resource.Retry(1*time.Minute, func() *resource.RetryError {
return retryTime(retryFunc, 1)
}

func retryTime(retryFunc func() error, minutes int) error {
return resource.Retry(time.Duration(minutes)*time.Minute, func() *resource.RetryError {
err := retryFunc()
if err == nil {
return nil
Expand Down

0 comments on commit 2c8dbac

Please sign in to comment.