Commit f6660e8a authored by Mitchell Hashimoto's avatar Mitchell Hashimoto

post-processor/vagrant-cloud: retry uploads [GH-2167]

parent d9fceaf3
...@@ -2,6 +2,8 @@ package vagrantcloud ...@@ -2,6 +2,8 @@ package vagrantcloud
import ( import (
"fmt" "fmt"
"time"
"github.com/mitchellh/multistep" "github.com/mitchellh/multistep"
"github.com/mitchellh/packer/packer" "github.com/mitchellh/packer/packer"
) )
...@@ -17,13 +19,38 @@ func (s *stepUpload) Run(state multistep.StateBag) multistep.StepAction { ...@@ -17,13 +19,38 @@ func (s *stepUpload) Run(state multistep.StateBag) multistep.StepAction {
url := upload.UploadPath url := upload.UploadPath
ui.Say(fmt.Sprintf("Uploading box: %s", artifactFilePath)) ui.Say(fmt.Sprintf("Uploading box: %s", artifactFilePath))
ui.Message(
"Depending on your internet connection and the size of the box,\n" +
"this may take some time")
ui.Message("Depending on your internet connection and the size of the box, this may take some time") var finalErr error
for i := 0; i < 3; i++ {
if i > 0 {
ui.Message(fmt.Sprintf("Uploading box, attempt %d", i+1))
}
resp, err := client.Upload(artifactFilePath, url) resp, err := client.Upload(artifactFilePath, url)
if err != nil {
finalErr = err
ui.Message(fmt.Sprintf(
"Error uploading box! Will retry in 10 seconds. Error: %s", err))
time.Sleep(10 * time.Second)
continue
}
if resp.StatusCode != 200 {
finalErr = fmt.Errorf("bad HTTP status: %d", resp.StatusCode)
ui.Message(fmt.Sprintf(
"Error uploading box! Will retry in 10 seconds. Status: %d",
resp.StatusCode))
time.Sleep(10 * time.Second)
continue
}
finalErr = nil
}
if err != nil || (resp.StatusCode != 200) { if finalErr != nil {
state.Put("error", fmt.Errorf("Error uploading Box: %s", err)) state.Put("error", finalErr)
return multistep.ActionHalt return multistep.ActionHalt
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment