Skip to content
Permalink
Browse files
Merge pull request #43 from svanharmelen/dev
Tweak the async logic
  • Loading branch information
Sander van Harmelen committed Dec 3, 2015
2 parents 104168f + 60afae5 commit eaf4e42852ca95fdd2ad70e18abad8ccb55bb611
Showing 135 changed files with 2,846 additions and 4,107 deletions.
@@ -333,15 +333,13 @@ func (s *AccountService) DeleteAccount(p *DeleteAccountParams) (*DeleteAccountRe

// If we have a async client, we need to wait for the async result
if s.cs.async {
b, warn, err := s.cs.GetAsyncJobResult(r.JobID, s.cs.timeout)
b, err := s.cs.GetAsyncJobResult(r.JobID, s.cs.timeout)
if err != nil {
if err == AsyncTimeoutErr {
return &r, err
}
return nil, err
}
// If 'warn' has a value it means the job is running longer than the configured
// timeout, the resonse will contain the jobid of the running async job
if warn != nil {
return &r, warn
}

if err := json.Unmarshal(b, &r); err != nil {
return nil, err
@@ -616,15 +614,13 @@ func (s *AccountService) DisableAccount(p *DisableAccountParams) (*DisableAccoun

// If we have a async client, we need to wait for the async result
if s.cs.async {
b, warn, err := s.cs.GetAsyncJobResult(r.JobID, s.cs.timeout)
b, err := s.cs.GetAsyncJobResult(r.JobID, s.cs.timeout)
if err != nil {
if err == AsyncTimeoutErr {
return &r, err
}
return nil, err
}
// If 'warn' has a value it means the job is running longer than the configured
// timeout, the resonse will contain the jobid of the running async job
if warn != nil {
return &r, warn
}

b, err = getRawValue(b)
if err != nil {
@@ -1367,15 +1363,13 @@ func (s *AccountService) MarkDefaultZoneForAccount(p *MarkDefaultZoneForAccountP

// If we have a async client, we need to wait for the async result
if s.cs.async {
b, warn, err := s.cs.GetAsyncJobResult(r.JobID, s.cs.timeout)
b, err := s.cs.GetAsyncJobResult(r.JobID, s.cs.timeout)
if err != nil {
if err == AsyncTimeoutErr {
return &r, err
}
return nil, err
}
// If 'warn' has a value it means the job is running longer than the configured
// timeout, the resonse will contain the jobid of the running async job
if warn != nil {
return &r, warn
}

b, err = getRawValue(b)
if err != nil {
@@ -1532,15 +1526,13 @@ func (s *AccountService) AddAccountToProject(p *AddAccountToProjectParams) (*Add

// If we have a async client, we need to wait for the async result
if s.cs.async {
b, warn, err := s.cs.GetAsyncJobResult(r.JobID, s.cs.timeout)
b, err := s.cs.GetAsyncJobResult(r.JobID, s.cs.timeout)
if err != nil {
if err == AsyncTimeoutErr {
return &r, err
}
return nil, err
}
// If 'warn' has a value it means the job is running longer than the configured
// timeout, the resonse will contain the jobid of the running async job
if warn != nil {
return &r, warn
}

if err := json.Unmarshal(b, &r); err != nil {
return nil, err
@@ -1613,15 +1605,13 @@ func (s *AccountService) DeleteAccountFromProject(p *DeleteAccountFromProjectPar

// If we have a async client, we need to wait for the async result
if s.cs.async {
b, warn, err := s.cs.GetAsyncJobResult(r.JobID, s.cs.timeout)
b, err := s.cs.GetAsyncJobResult(r.JobID, s.cs.timeout)
if err != nil {
if err == AsyncTimeoutErr {
return &r, err
}
return nil, err
}
// If 'warn' has a value it means the job is running longer than the configured
// timeout, the resonse will contain the jobid of the running async job
if warn != nil {
return &r, warn
}

if err := json.Unmarshal(b, &r); err != nil {
return nil, err
@@ -160,15 +160,13 @@ func (s *AddressService) AssociateIpAddress(p *AssociateIpAddressParams) (*Assoc

// If we have a async client, we need to wait for the async result
if s.cs.async {
b, warn, err := s.cs.GetAsyncJobResult(r.JobID, s.cs.timeout)
b, err := s.cs.GetAsyncJobResult(r.JobID, s.cs.timeout)
if err != nil {
if err == AsyncTimeoutErr {
return &r, err
}
return nil, err
}
// If 'warn' has a value it means the job is running longer than the configured
// timeout, the resonse will contain the jobid of the running async job
if warn != nil {
return &r, warn
}

b, err = getRawValue(b)
if err != nil {
@@ -273,15 +271,13 @@ func (s *AddressService) DisassociateIpAddress(p *DisassociateIpAddressParams) (

// If we have a async client, we need to wait for the async result
if s.cs.async {
b, warn, err := s.cs.GetAsyncJobResult(r.JobID, s.cs.timeout)
b, err := s.cs.GetAsyncJobResult(r.JobID, s.cs.timeout)
if err != nil {
if err == AsyncTimeoutErr {
return &r, err
}
return nil, err
}
// If 'warn' has a value it means the job is running longer than the configured
// timeout, the resonse will contain the jobid of the running async job
if warn != nil {
return &r, warn
}

if err := json.Unmarshal(b, &r); err != nil {
return nil, err
@@ -747,15 +743,13 @@ func (s *AddressService) UpdateIpAddress(p *UpdateIpAddressParams) (*UpdateIpAdd

// If we have a async client, we need to wait for the async result
if s.cs.async {
b, warn, err := s.cs.GetAsyncJobResult(r.JobID, s.cs.timeout)
b, err := s.cs.GetAsyncJobResult(r.JobID, s.cs.timeout)
if err != nil {
if err == AsyncTimeoutErr {
return &r, err
}
return nil, err
}
// If 'warn' has a value it means the job is running longer than the configured
// timeout, the resonse will contain the jobid of the running async job
if warn != nil {
return &r, warn
}

b, err = getRawValue(b)
if err != nil {
@@ -115,15 +115,13 @@ func (s *AffinityGroupService) CreateAffinityGroup(p *CreateAffinityGroupParams)

// If we have a async client, we need to wait for the async result
if s.cs.async {
b, warn, err := s.cs.GetAsyncJobResult(r.JobID, s.cs.timeout)
b, err := s.cs.GetAsyncJobResult(r.JobID, s.cs.timeout)
if err != nil {
if err == AsyncTimeoutErr {
return &r, err
}
return nil, err
}
// If 'warn' has a value it means the job is running longer than the configured
// timeout, the resonse will contain the jobid of the running async job
if warn != nil {
return &r, warn
}

b, err = getRawValue(b)
if err != nil {
@@ -227,15 +225,13 @@ func (s *AffinityGroupService) DeleteAffinityGroup(p *DeleteAffinityGroupParams)

// If we have a async client, we need to wait for the async result
if s.cs.async {
b, warn, err := s.cs.GetAsyncJobResult(r.JobID, s.cs.timeout)
b, err := s.cs.GetAsyncJobResult(r.JobID, s.cs.timeout)
if err != nil {
if err == AsyncTimeoutErr {
return &r, err
}
return nil, err
}
// If 'warn' has a value it means the job is running longer than the configured
// timeout, the resonse will contain the jobid of the running async job
if warn != nil {
return &r, warn
}

if err := json.Unmarshal(b, &r); err != nil {
return nil, err
@@ -566,15 +562,13 @@ func (s *AffinityGroupService) UpdateVMAffinityGroup(p *UpdateVMAffinityGroupPar

// If we have a async client, we need to wait for the async result
if s.cs.async {
b, warn, err := s.cs.GetAsyncJobResult(r.JobID, s.cs.timeout)
b, err := s.cs.GetAsyncJobResult(r.JobID, s.cs.timeout)
if err != nil {
if err == AsyncTimeoutErr {
return &r, err
}
return nil, err
}
// If 'warn' has a value it means the job is running longer than the configured
// timeout, the resonse will contain the jobid of the running async job
if warn != nil {
return &r, warn
}

b, err = getRawValue(b)
if err != nil {
@@ -471,15 +471,13 @@ func (s *AlertService) GenerateAlert(p *GenerateAlertParams) (*GenerateAlertResp

// If we have a async client, we need to wait for the async result
if s.cs.async {
b, warn, err := s.cs.GetAsyncJobResult(r.JobID, s.cs.timeout)
b, err := s.cs.GetAsyncJobResult(r.JobID, s.cs.timeout)
if err != nil {
if err == AsyncTimeoutErr {
return &r, err
}
return nil, err
}
// If 'warn' has a value it means the job is running longer than the configured
// timeout, the resonse will contain the jobid of the running async job
if warn != nil {
return &r, warn
}

if err := json.Unmarshal(b, &r); err != nil {
return nil, err
@@ -20,6 +20,7 @@ import (
"encoding/json"
"net/url"
"strconv"
"time"
)

type QueryAsyncJobResultParams struct {
@@ -62,9 +63,10 @@ func (s *AsyncjobService) QueryAsyncJobResult(p *QueryAsyncJobResultParams) (*Qu
// We should be able to retry on failure as this call is idempotent
for i := 0; i < 3; i++ {
resp, err = s.cs.newRequest("queryAsyncJobResult", p.toURLValues())
if err != nil {
continue
if err == nil {
break
}
time.Sleep(500 * time.Millisecond)
}
if err != nil {
return nil, err

0 comments on commit eaf4e42

Please sign in to comment.