Skip to content
This repository has been archived by the owner on Jun 27, 2021. It is now read-only.

Commit

Permalink
Release v0.1.44
Browse files Browse the repository at this point in the history
Signed-off-by: Chase Sillevis <[email protected]>
  • Loading branch information
DeviaVir committed Apr 15, 2020
1 parent 120324d commit 8f04384
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 12 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ GOVERSION := 1.14
PROJECT := github.com/DeviaVir/terraform-provider-gsuite
OWNER := $(notdir $(patsubst %/,%,$(dir $(PROJECT))))
NAME := $(notdir $(PROJECT))
VERSION := 0.1.42
VERSION := 0.1.44
EXTERNAL_TOOLS = \
github.com/golang/dep/cmd/dep

Expand Down
2 changes: 1 addition & 1 deletion gsuite/resource_group_settings.go
Original file line number Diff line number Diff line change
Expand Up @@ -734,7 +734,7 @@ func resourceGroupSettingsRead(d *schema.ResourceData, meta interface{}) error {

var err error
var groupSetting *groupSettings.Groups
err = retry(func() error {
err = retryInvalid(func() error {
groupSetting, err = config.groupSettings.Groups.Get(d.Get("email").(string)).Do()
return err
}, config.TimeoutMinutes)
Expand Down
38 changes: 28 additions & 10 deletions gsuite/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,35 +28,48 @@ func handleNotFoundError(err error, d *schema.ResourceData, resource string) err
}

func retry(retryFunc func() error, minutes int) error {
return retryTime(retryFunc, minutes, false, false)
return retryTime(retryFunc, minutes, false, false, false)
}

func retryNotFound(retryFunc func() error, minutes int) error {
return retryTime(retryFunc, minutes, true, false)
return retryTime(retryFunc, minutes, true, false, false)
}

func retryInvalid(retryFunc func() error, minutes int) error {
return retryTime(retryFunc, minutes, false, false, true)
}

func retryPassDuplicate(retryFunc func() error, minutes int) error {
return retryTime(retryFunc, minutes, true, true)
return retryTime(retryFunc, minutes, true, true, false)
}

func retryTime(retryFunc func() error, minutes int, retryNotFound bool, retryPassDuplicate bool) error {
func retryTime(retryFunc func() error, minutes int, retryNotFound bool, retryPassDuplicate bool, retryInvalid bool) error {
wait := 1
return resource.Retry(time.Duration(minutes)*time.Minute, func() *resource.RetryError {
err := retryFunc()
if err == nil {
return nil
}

rand.Seed(time.Now().UnixNano())
randomNumberMiliseconds := rand.Intn(1001)

if gerr, ok := err.(*googleapi.Error); ok && (gerr.Code == 500 || gerr.Code == 502 || gerr.Code == 503) {
log.Printf("[DEBUG] Retrying server error code...")
time.Sleep(time.Duration(wait)*time.Second + time.Duration(randomNumberMiliseconds))
wait = wait * 2
return resource.RetryableError(gerr)
}

if retryPassDuplicate {
if gerr, ok := err.(*googleapi.Error); ok && (gerr.Errors[0].Reason == "quotaExceeded" || gerr.Code == 401 || gerr.Code == 429 || gerr.Code == 500 || gerr.Code == 502 || gerr.Code == 503) {
if gerr, ok := err.(*googleapi.Error); ok && (gerr.Errors[0].Reason == "quotaExceeded" || gerr.Code == 401 || gerr.Code == 429) {
log.Printf("[DEBUG] Retrying quota/server error code...")
time.Sleep(time.Duration(wait)*time.Second + time.Duration(randomNumberMiliseconds))
wait = wait * 2
return resource.RetryableError(gerr)
}
} else {
if gerr, ok := err.(*googleapi.Error); ok && (gerr.Errors[0].Reason == "quotaExceeded" || gerr.Code == 401 || gerr.Code == 409 || gerr.Code == 429 || gerr.Code == 500 || gerr.Code == 502 || gerr.Code == 503) {
if gerr, ok := err.(*googleapi.Error); ok && (gerr.Errors[0].Reason == "quotaExceeded" || gerr.Code == 401 || gerr.Code == 409 || gerr.Code == 429) {
log.Printf("[DEBUG] Retrying quota/server error code...")
time.Sleep(time.Duration(wait)*time.Second + time.Duration(randomNumberMiliseconds))
wait = wait * 2
Expand All @@ -72,6 +85,15 @@ func retryTime(retryFunc func() error, minutes int, retryNotFound bool, retryPas
}
}

if retryInvalid {
if gerr, ok := err.(*googleapi.Error); ok && (gerr.Errors[0].Reason == "invalid" || gerr.Code == 400) {
log.Printf("[DEBUG] Retrying invalid error code...")
time.Sleep(time.Duration(wait)*time.Second + time.Duration(randomNumberMiliseconds))
wait = wait * 2
return resource.RetryableError(gerr)
}
}

// Deal with the broken API
if strings.Contains(fmt.Sprintf("%s", err), "Invalid Input: Bad request for \"") && strings.Contains(fmt.Sprintf("%s", err), "\"code\":400") {
log.Printf("[DEBUG] Retrying invalid response from API")
Expand All @@ -85,10 +107,6 @@ func retryTime(retryFunc func() error, minutes int, retryNotFound bool, retryPas
log.Printf("[DEBUG] Retrying due to eventual consistency")
return resource.RetryableError(err)
}
if strings.Contains(fmt.Sprintf("%s", err), "Invalid Value, invalid") {
log.Printf("[DEBUG] G Suite API could be tripping up, retrying")
return resource.RetryableError(err)
}

return resource.NonRetryableError(err)
})
Expand Down

0 comments on commit 8f04384

Please sign in to comment.