Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add retry on cloud functions error when pulling source from GCS #453

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion google/common_operation.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,15 @@ import (
cloudresourcemanager "google.golang.org/api/cloudresourcemanager/v1"
)

// Wraps Op.Error in an implementation of built-in Error
type CommonOpError struct {
*cloudresourcemanager.Status
}

func (e *CommonOpError) Error() string {
return fmt.Sprintf("Error code %v, message: %s", e.Code, e.Message)
}

type Waiter interface {
// State returns the current status of the operation.
State() string
Expand Down Expand Up @@ -56,7 +65,7 @@ func (w *CommonOperationWaiter) State() string {

func (w *CommonOperationWaiter) Error() error {
if w != nil && w.Op.Error != nil {
return fmt.Errorf("Error code %v, message: %s", w.Op.Error.Code, w.Op.Error.Message)
return &CommonOpError{w.Op.Error}
}
return nil
}
Expand Down
9 changes: 9 additions & 0 deletions google/error_retry_predicates.go
Original file line number Diff line number Diff line change
Expand Up @@ -257,3 +257,12 @@ func isPeeringOperationInProgress(err error) (bool, string) {
}
return false, ""
}

func isCloudFunctionsSourceCodeError(err error) (bool, string) {
if operr, ok := err.(*CommonOpError); ok {
if operr.Code == 3 && operr.Message == "Failed to retrieve function source code" {
return true, fmt.Sprintf("Retry on Function failing to pull code from GCS")
}
}
return false, ""
}