Skip to content

Commit

Permalink
Retry slug uploads when error is encountered (#356)
Browse files Browse the repository at this point in the history
* Retry slug uploads when error is encountered

* More descriptive error on timeout when retrying slug upload
  • Loading branch information
mars authored Dec 9, 2022
1 parent 94318ec commit 7f1cea7
Showing 1 changed file with 15 additions and 3 deletions.
18 changes: 15 additions & 3 deletions heroku/resource_heroku_slug.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,10 @@ import (
"os"
"regexp"
"strings"
"time"

"github.com/hashicorp/go-uuid"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation"
heroku "github.com/heroku/heroku-go/v5"
Expand Down Expand Up @@ -245,9 +247,19 @@ func resourceHerokuSlugCreate(d *schema.ResourceData, meta interface{}) error {
// Optionally upload slug before setting ID, so that an upload failure
// causes a resource creation error, is not saved in state.
if filePath != "" {
err := uploadSlug(filePath, slug.Blob.Method, slug.Blob.URL)
if err != nil {
return err
var uploadErr error
retryErr := resource.Retry(d.Timeout(schema.TimeoutCreate), func() *resource.RetryError {
uploadErr = uploadSlug(filePath, slug.Blob.Method, slug.Blob.URL)
if uploadErr != nil {
log.Printf("[DEBUG] Error uploading slug: %s", uploadErr.Error())
log.Printf("[DEBUG] Retry uploading slug")
time.Sleep(10 * time.Second)
return resource.RetryableError(uploadErr)
}
return nil
})
if retryErr != nil {
return fmt.Errorf("Error uploading slug: %s, last error: %s", retryErr, uploadErr)
}
}

Expand Down

0 comments on commit 7f1cea7

Please sign in to comment.