Skip to content

Commit 5898798

Browse files
committed
refac(mariadb): Use new WaitHelper for waiters
STACKITSDK-380 Signed-off-by: Alexander Dahmen <alexander.dahmen@inovex.de>
1 parent 91bb7bd commit 5898798

4 files changed

Lines changed: 33 additions & 33 deletions

File tree

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -217,6 +217,8 @@
217217
- **Dependencies:** Bump STACKIT SDK core module from `v0.24.1` to `v0.25.0`
218218
- [v0.28.2](services/mariadb/CHANGELOG.md#v282)
219219
- **Dependencies:** Bump STACKIT SDK core module from `v0.25.0` to `v0.26.0`
220+
- [v0.29.0](services/mariadb/CHANGELOG.md#v290)
221+
- **Improvement:** Use new WaiterHelper for Logs waiters
220222
- `modelserving`:
221223
- [v0.8.3](services/modelserving/CHANGELOG.md#v083)
222224
- **Dependencies:** Bump STACKIT SDK core module from `v0.24.0` to `v0.24.1`

services/mariadb/CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
## v0.29.0
2+
- **Improvement:** Use new WaiterHelper for Logs waiters
3+
14
## v0.28.2
25
- **Dependencies:** Bump STACKIT SDK core module from `v0.25.0` to `v0.26.0`
36

services/mariadb/VERSION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
v0.28.2
1+
v0.29.0

services/mariadb/v1api/wait/wait.go

Lines changed: 27 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package wait
22

33
import (
44
"context"
5+
"errors"
56
"fmt"
67
"net/http"
78
"strings"
@@ -23,44 +24,38 @@ const (
2324

2425
// CreateInstanceWaitHandler will wait for instance creation
2526
func CreateInstanceWaitHandler(ctx context.Context, a mariadb.DefaultAPI, projectId, instanceId string) *wait.AsyncActionHandler[mariadb.Instance] {
26-
handler := wait.New(func() (waitFinished bool, response *mariadb.Instance, err error) {
27-
s, err := a.GetInstance(ctx, projectId, instanceId).Execute()
28-
if err != nil {
29-
return false, nil, err
30-
}
31-
if s.Status == nil {
32-
return false, nil, fmt.Errorf("create failed for instance with id %s. The response is not valid: the status is missing", instanceId)
33-
}
34-
switch *s.Status {
35-
case INSTANCESTATUS_ACTIVE:
36-
return true, s, nil
37-
case INSTANCESTATUS_FAILED:
38-
return true, s, fmt.Errorf("create failed for instance with id %s: %s", instanceId, s.LastOperation.Description)
39-
}
40-
return false, nil, nil
41-
})
27+
waitConfig := wait.WaiterHelper[mariadb.Instance, string]{
28+
FetchInstance: a.GetInstance(ctx, projectId, instanceId).Execute,
29+
GetState: func(s *mariadb.Instance) (string, error) {
30+
if s == nil || s.Status == nil {
31+
return "", errors.New("response or status is nil")
32+
}
33+
return *s.Status, nil
34+
},
35+
ActiveState: []string{INSTANCESTATUS_ACTIVE},
36+
ErrorState: []string{INSTANCESTATUS_FAILED},
37+
}
38+
39+
handler := wait.New(waitConfig.Wait())
4240
handler.SetTimeout(45 * time.Minute)
4341
return handler
4442
}
4543

4644
// PartialUpdateInstanceWaitHandler will wait for instance update
4745
func PartialUpdateInstanceWaitHandler(ctx context.Context, a mariadb.DefaultAPI, projectId, instanceId string) *wait.AsyncActionHandler[mariadb.Instance] {
48-
handler := wait.New(func() (waitFinished bool, response *mariadb.Instance, err error) {
49-
s, err := a.GetInstance(ctx, projectId, instanceId).Execute()
50-
if err != nil {
51-
return false, nil, err
52-
}
53-
if s.Status == nil {
54-
return false, nil, fmt.Errorf("update failed for instance with id %s. The response is not valid: the instance id or the status are missing", instanceId)
55-
}
56-
switch *s.Status {
57-
case INSTANCESTATUS_ACTIVE:
58-
return true, s, nil
59-
case INSTANCESTATUS_FAILED:
60-
return true, s, fmt.Errorf("update failed for instance with id %s: %s", instanceId, s.LastOperation.Description)
61-
}
62-
return false, nil, nil
63-
})
46+
waitConfig := wait.WaiterHelper[mariadb.Instance, string]{
47+
FetchInstance: a.GetInstance(ctx, projectId, instanceId).Execute,
48+
GetState: func(s *mariadb.Instance) (string, error) {
49+
if s == nil || s.Status == nil {
50+
return "", errors.New("response or status is nil")
51+
}
52+
return *s.Status, nil
53+
},
54+
ActiveState: []string{INSTANCESTATUS_ACTIVE},
55+
ErrorState: []string{INSTANCESTATUS_FAILED},
56+
}
57+
58+
handler := wait.New(waitConfig.Wait())
6459
handler.SetTimeout(45 * time.Minute)
6560
return handler
6661
}

0 commit comments

Comments
 (0)