Skip to content

Commit 3ae820c

Browse files
committed
fix(cockpit): remove WaitForAlert and keep only WaitForPreconfiguredAlerts
1 parent 417d470 commit 3ae820c

File tree

1 file changed

+0
-54
lines changed

1 file changed

+0
-54
lines changed

api/cockpit/v1/cockpit_utils.go

Lines changed: 0 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -13,60 +13,6 @@ const (
1313
defaultTimeout = 5 * time.Minute
1414
)
1515

16-
// WaitForAlertRequest is used by WaitForAlert method.
17-
type WaitForAlertRequest struct {
18-
Region scw.Region
19-
AlertID string
20-
Timeout *time.Duration
21-
RetryInterval *time.Duration
22-
}
23-
24-
// WaitForAlert waits for the alert to be in a "terminal state" before returning.
25-
// This function can be used to wait for an alert to be enabled or disabled.
26-
func (s *RegionalAPI) WaitForAlert(req *WaitForAlertRequest, opts ...scw.RequestOption) (*Alert, error) {
27-
timeout := defaultTimeout
28-
if req.Timeout != nil {
29-
timeout = *req.Timeout
30-
}
31-
retryInterval := defaultRetryInterval
32-
if req.RetryInterval != nil {
33-
retryInterval = *req.RetryInterval
34-
}
35-
36-
terminalStatus := map[AlertStatus]struct{}{
37-
AlertStatusEnabled: {},
38-
AlertStatusDisabled: {},
39-
}
40-
41-
alert, err := async.WaitSync(&async.WaitSyncConfig{
42-
Get: func() (any, bool, error) {
43-
// List all alerts and find the one with matching ID
44-
res, err := s.ListAlerts(&RegionalAPIListAlertsRequest{
45-
Region: req.Region,
46-
}, opts...)
47-
if err != nil {
48-
return nil, false, err
49-
}
50-
51-
// Find the alert by ID
52-
for _, alert := range res.Alerts {
53-
if alert.ID == req.AlertID {
54-
_, isTerminal := terminalStatus[alert.RuleStatus]
55-
return alert, isTerminal, nil
56-
}
57-
}
58-
59-
return nil, false, errors.New("alert not found")
60-
},
61-
Timeout: timeout,
62-
IntervalStrategy: async.LinearIntervalStrategy(retryInterval),
63-
})
64-
if err != nil {
65-
return nil, errors.Wrap(err, "waiting for alert failed")
66-
}
67-
return alert.(*Alert), nil
68-
}
69-
7016
// WaitForPreconfiguredAlertsRequest is used by WaitForPreconfiguredAlerts method.
7117
type WaitForPreconfiguredAlertsRequest struct {
7218
Region scw.Region

0 commit comments

Comments
 (0)