-
Notifications
You must be signed in to change notification settings - Fork 84
/
waiter.go
44 lines (40 loc) · 1023 Bytes
/
waiter.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
package credloader
import (
"errors"
"time"
"github.com/kyma-incubator/compass/components/director/pkg/log"
)
// WaitForCertCache waits for a CertCache to get populated with data
func WaitForCertCache(cache CertCache) error {
ticker := time.NewTicker(time.Second)
timeout := time.After(time.Second * 15)
for {
select {
case <-ticker.C:
if cache.Get() == nil {
log.D().Info("Waiting for certificate cache to load, sleeping for 1 second")
} else {
return nil
}
case <-timeout:
return errors.New("timeout waiting for cache to load")
}
}
}
// WaitForKeyCache waits for a KeysCache to get populated with data
func WaitForKeyCache(cache KeysCache) error {
ticker := time.NewTicker(time.Second)
timeout := time.After(time.Second * 15)
for {
select {
case <-ticker.C:
if cache.Get() == nil {
log.D().Info("Waiting for key cache to load, sleeping for 1 second")
} else {
return nil
}
case <-timeout:
return errors.New("timeout waiting for cache to load")
}
}
}