Skip to content

Commit 5cd72f6

Browse files
author
Sander van Harmelen
committed
Improve async job handling and increase default timeout
1 parent 104168f commit 5cd72f6

135 files changed

Lines changed: 2713 additions & 4010 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

cloudstack/AccountService.go

Lines changed: 20 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -333,15 +333,13 @@ func (s *AccountService) DeleteAccount(p *DeleteAccountParams) (*DeleteAccountRe
333333

334334
// If we have a async client, we need to wait for the async result
335335
if s.cs.async {
336-
b, warn, err := s.cs.GetAsyncJobResult(r.JobID, s.cs.timeout)
336+
b, err := s.cs.GetAsyncJobResult(r.JobID, s.cs.timeout)
337337
if err != nil {
338+
if err == AsyncTimeoutErr {
339+
return &r, err
340+
}
338341
return nil, err
339342
}
340-
// If 'warn' has a value it means the job is running longer than the configured
341-
// timeout, the resonse will contain the jobid of the running async job
342-
if warn != nil {
343-
return &r, warn
344-
}
345343

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

617615
// If we have a async client, we need to wait for the async result
618616
if s.cs.async {
619-
b, warn, err := s.cs.GetAsyncJobResult(r.JobID, s.cs.timeout)
617+
b, err := s.cs.GetAsyncJobResult(r.JobID, s.cs.timeout)
620618
if err != nil {
619+
if err == AsyncTimeoutErr {
620+
return &r, err
621+
}
621622
return nil, err
622623
}
623-
// If 'warn' has a value it means the job is running longer than the configured
624-
// timeout, the resonse will contain the jobid of the running async job
625-
if warn != nil {
626-
return &r, warn
627-
}
628624

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

13681364
// If we have a async client, we need to wait for the async result
13691365
if s.cs.async {
1370-
b, warn, err := s.cs.GetAsyncJobResult(r.JobID, s.cs.timeout)
1366+
b, err := s.cs.GetAsyncJobResult(r.JobID, s.cs.timeout)
13711367
if err != nil {
1368+
if err == AsyncTimeoutErr {
1369+
return &r, err
1370+
}
13721371
return nil, err
13731372
}
1374-
// If 'warn' has a value it means the job is running longer than the configured
1375-
// timeout, the resonse will contain the jobid of the running async job
1376-
if warn != nil {
1377-
return &r, warn
1378-
}
13791373

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

15331527
// If we have a async client, we need to wait for the async result
15341528
if s.cs.async {
1535-
b, warn, err := s.cs.GetAsyncJobResult(r.JobID, s.cs.timeout)
1529+
b, err := s.cs.GetAsyncJobResult(r.JobID, s.cs.timeout)
15361530
if err != nil {
1531+
if err == AsyncTimeoutErr {
1532+
return &r, err
1533+
}
15371534
return nil, err
15381535
}
1539-
// If 'warn' has a value it means the job is running longer than the configured
1540-
// timeout, the resonse will contain the jobid of the running async job
1541-
if warn != nil {
1542-
return &r, warn
1543-
}
15441536

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

16141606
// If we have a async client, we need to wait for the async result
16151607
if s.cs.async {
1616-
b, warn, err := s.cs.GetAsyncJobResult(r.JobID, s.cs.timeout)
1608+
b, err := s.cs.GetAsyncJobResult(r.JobID, s.cs.timeout)
16171609
if err != nil {
1610+
if err == AsyncTimeoutErr {
1611+
return &r, err
1612+
}
16181613
return nil, err
16191614
}
1620-
// If 'warn' has a value it means the job is running longer than the configured
1621-
// timeout, the resonse will contain the jobid of the running async job
1622-
if warn != nil {
1623-
return &r, warn
1624-
}
16251615

16261616
if err := json.Unmarshal(b, &r); err != nil {
16271617
return nil, err

cloudstack/AddressService.go

Lines changed: 12 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -160,15 +160,13 @@ func (s *AddressService) AssociateIpAddress(p *AssociateIpAddressParams) (*Assoc
160160

161161
// If we have a async client, we need to wait for the async result
162162
if s.cs.async {
163-
b, warn, err := s.cs.GetAsyncJobResult(r.JobID, s.cs.timeout)
163+
b, err := s.cs.GetAsyncJobResult(r.JobID, s.cs.timeout)
164164
if err != nil {
165+
if err == AsyncTimeoutErr {
166+
return &r, err
167+
}
165168
return nil, err
166169
}
167-
// If 'warn' has a value it means the job is running longer than the configured
168-
// timeout, the resonse will contain the jobid of the running async job
169-
if warn != nil {
170-
return &r, warn
171-
}
172170

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

274272
// If we have a async client, we need to wait for the async result
275273
if s.cs.async {
276-
b, warn, err := s.cs.GetAsyncJobResult(r.JobID, s.cs.timeout)
274+
b, err := s.cs.GetAsyncJobResult(r.JobID, s.cs.timeout)
277275
if err != nil {
276+
if err == AsyncTimeoutErr {
277+
return &r, err
278+
}
278279
return nil, err
279280
}
280-
// If 'warn' has a value it means the job is running longer than the configured
281-
// timeout, the resonse will contain the jobid of the running async job
282-
if warn != nil {
283-
return &r, warn
284-
}
285281

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

748744
// If we have a async client, we need to wait for the async result
749745
if s.cs.async {
750-
b, warn, err := s.cs.GetAsyncJobResult(r.JobID, s.cs.timeout)
746+
b, err := s.cs.GetAsyncJobResult(r.JobID, s.cs.timeout)
751747
if err != nil {
748+
if err == AsyncTimeoutErr {
749+
return &r, err
750+
}
752751
return nil, err
753752
}
754-
// If 'warn' has a value it means the job is running longer than the configured
755-
// timeout, the resonse will contain the jobid of the running async job
756-
if warn != nil {
757-
return &r, warn
758-
}
759753

760754
b, err = getRawValue(b)
761755
if err != nil {

cloudstack/AffinityGroupService.go

Lines changed: 12 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -115,15 +115,13 @@ func (s *AffinityGroupService) CreateAffinityGroup(p *CreateAffinityGroupParams)
115115

116116
// If we have a async client, we need to wait for the async result
117117
if s.cs.async {
118-
b, warn, err := s.cs.GetAsyncJobResult(r.JobID, s.cs.timeout)
118+
b, err := s.cs.GetAsyncJobResult(r.JobID, s.cs.timeout)
119119
if err != nil {
120+
if err == AsyncTimeoutErr {
121+
return &r, err
122+
}
120123
return nil, err
121124
}
122-
// If 'warn' has a value it means the job is running longer than the configured
123-
// timeout, the resonse will contain the jobid of the running async job
124-
if warn != nil {
125-
return &r, warn
126-
}
127125

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

228226
// If we have a async client, we need to wait for the async result
229227
if s.cs.async {
230-
b, warn, err := s.cs.GetAsyncJobResult(r.JobID, s.cs.timeout)
228+
b, err := s.cs.GetAsyncJobResult(r.JobID, s.cs.timeout)
231229
if err != nil {
230+
if err == AsyncTimeoutErr {
231+
return &r, err
232+
}
232233
return nil, err
233234
}
234-
// If 'warn' has a value it means the job is running longer than the configured
235-
// timeout, the resonse will contain the jobid of the running async job
236-
if warn != nil {
237-
return &r, warn
238-
}
239235

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

567563
// If we have a async client, we need to wait for the async result
568564
if s.cs.async {
569-
b, warn, err := s.cs.GetAsyncJobResult(r.JobID, s.cs.timeout)
565+
b, err := s.cs.GetAsyncJobResult(r.JobID, s.cs.timeout)
570566
if err != nil {
567+
if err == AsyncTimeoutErr {
568+
return &r, err
569+
}
571570
return nil, err
572571
}
573-
// If 'warn' has a value it means the job is running longer than the configured
574-
// timeout, the resonse will contain the jobid of the running async job
575-
if warn != nil {
576-
return &r, warn
577-
}
578572

579573
b, err = getRawValue(b)
580574
if err != nil {

cloudstack/AlertService.go

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -471,15 +471,13 @@ func (s *AlertService) GenerateAlert(p *GenerateAlertParams) (*GenerateAlertResp
471471

472472
// If we have a async client, we need to wait for the async result
473473
if s.cs.async {
474-
b, warn, err := s.cs.GetAsyncJobResult(r.JobID, s.cs.timeout)
474+
b, err := s.cs.GetAsyncJobResult(r.JobID, s.cs.timeout)
475475
if err != nil {
476+
if err == AsyncTimeoutErr {
477+
return &r, err
478+
}
476479
return nil, err
477480
}
478-
// If 'warn' has a value it means the job is running longer than the configured
479-
// timeout, the resonse will contain the jobid of the running async job
480-
if warn != nil {
481-
return &r, warn
482-
}
483481

484482
if err := json.Unmarshal(b, &r); err != nil {
485483
return nil, err

cloudstack/AsyncjobService.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import (
2020
"encoding/json"
2121
"net/url"
2222
"strconv"
23+
"time"
2324
)
2425

2526
type QueryAsyncJobResultParams struct {
@@ -62,9 +63,10 @@ func (s *AsyncjobService) QueryAsyncJobResult(p *QueryAsyncJobResultParams) (*Qu
6263
// We should be able to retry on failure as this call is idempotent
6364
for i := 0; i < 3; i++ {
6465
resp, err = s.cs.newRequest("queryAsyncJobResult", p.toURLValues())
65-
if err != nil {
66-
continue
66+
if err == nil {
67+
break
6768
}
69+
time.Sleep(1 * time.Second)
6870
}
6971
if err != nil {
7072
return nil, err

0 commit comments

Comments
 (0)