Skip to content
New issue

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

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

Already on GitHub? # to your account

dataproc: better handle intermittent 503 errors from job status check #14

Merged
merged 1 commit into from
Feb 17, 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
29 changes: 29 additions & 0 deletions dataproc/job.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,33 @@ func SubmitJob(j hdfs.Job, client *http.Client, project, region, cluster string)
return nil
}

type unavalable503 struct {
body string
}

func (u unavalable503) Error() string {
return fmt.Sprintf("503 Unavailable %s", u.body)
}

func get(client *http.Client, resource string) (*job, error) {
var j *job
var err error
for i := 0; i < 5; i++ {
j, err = getJob(client, resource)
if err == nil {
return j, err
}
if _, ok := err.(unavalable503); ok {
log.Printf("retrying get. err:%s", err)
time.Sleep(10 * time.Second)
} else {
break
}
}
return j, err
}

func getJob(client *http.Client, resource string) (*job, error) {
resp, err := client.Get(resource)
if err != nil {
return nil, err
Expand All @@ -125,6 +151,9 @@ func get(client *http.Client, resource string) (*job, error) {
if err != nil {
return nil, err
}
if resp.StatusCode == 503 {
return nil, unavalable503{body: string(respBody)}
}
if resp.StatusCode != 200 {
log.Print(string(respBody))
return nil, fmt.Errorf("got status code %d", resp.StatusCode)
Expand Down