File tree Expand file tree Collapse file tree 1 file changed +50
-0
lines changed Expand file tree Collapse file tree 1 file changed +50
-0
lines changed Original file line number Diff line number Diff line change 1+ package lb
2+
3+ import (
4+ "time"
5+
6+ "github.com/scaleway/scaleway-sdk-go/internal/async"
7+ "github.com/scaleway/scaleway-sdk-go/internal/errors"
8+ "github.com/scaleway/scaleway-sdk-go/scw"
9+ )
10+
11+ // WaitForLbRequest is used by WaitForLb method.
12+ type WaitForLbRequest struct {
13+ LbID string
14+ Region scw.Region
15+ Timeout time.Duration
16+ }
17+
18+ // WaitForLb waits for the lb to be in a "terminal state" before returning.
19+ // This function can be used to wait for a lb to be ready for example.
20+ func (s * API ) WaitForLb (req * WaitForLbRequest ) (* Lb , error ) {
21+
22+ terminalStatus := map [LbStatus ]struct {}{
23+ LbStatusReady : {},
24+ LbStatusStopped : {},
25+ LbStatusError : {},
26+ LbStatusLocked : {},
27+ }
28+
29+ lb , err := async .WaitSync (& async.WaitSyncConfig {
30+ Get : func () (interface {}, error , bool ) {
31+ res , err := s .GetLb (& GetLbRequest {
32+ LbID : req .LbID ,
33+ Region : req .Region ,
34+ })
35+
36+ if err != nil {
37+ return nil , err , false
38+ }
39+ _ , isTerminal := terminalStatus [res .Status ]
40+
41+ return res , nil , isTerminal
42+ },
43+ Timeout : req .Timeout ,
44+ IntervalStrategy : async .LinearIntervalStrategy (5 * time .Second ),
45+ })
46+ if err != nil {
47+ return nil , errors .Wrap (err , "waiting for lb failed" )
48+ }
49+ return lb .(* Lb ), nil
50+ }
You can’t perform that action at this time.
0 commit comments