Skip to content

r/dedicated_server_*_task: retry on API 500/404 errors #134

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

Merged
merged 1 commit into from
Feb 6, 2020
Merged
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
30 changes: 27 additions & 3 deletions ovh/dedicated_server_task.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,33 @@ func waitForDedicatedServerTask(serviceName string, task *DedicatedServerTask, c
taskId := task.Id

refreshFunc := func() (interface{}, string, error) {
task, err := getDedicatedServerTask(serviceName, taskId, c)
if err != nil {
return taskId, "", err
var taskErr error
var task *DedicatedServerTask

// The Dedicated Server API often returns 500/404 errors
// in such case we retry to retrieve task status
// 404 may happen because of some inconsistency between the
// api endpoint call and the target region executing the task
retryErr := resource.Retry(5*time.Minute, func() *resource.RetryError {
var err error
task, err = getDedicatedServerTask(serviceName, taskId, c)
if err != nil {
if err.(*ovh.APIError).Code == 500 || err.(*ovh.APIError).Code == 404 {
// retry
return resource.RetryableError(err)
}
// other error dont retry and fail
taskErr = err
}
return nil
})

if retryErr != nil {
return taskId, "", retryErr
}

if taskErr != nil {
return taskId, "", taskErr
}

log.Printf("[INFO] Pending Task id %d on Dedicated %s status: %s", taskId, serviceName, task.Status)
Expand Down