blob: a2a7e5f033e9ebaedda380685aa3b37c2a38f2b9 (
plain)
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
45
|
package gitlab
import (
"time"
"github.com/cenkalti/backoff/v4"
log "github.com/sirupsen/logrus"
)
const (
// maxPollingTime is the maximum duration to try to call the Status API
maxPollingTime = 60 * time.Minute
)
// Poll tries to call the /internal/pages/status API endpoint once plus
// for `maxElapsedTime`
// TODO: Remove in https://gitlab.com/gitlab-org/gitlab-pages/-/issues/449
func (g *Gitlab) poll(interval, maxElapsedTime time.Duration) {
backOff := backoff.NewExponentialBackOff()
backOff.InitialInterval = interval
backOff.MaxElapsedTime = maxElapsedTime
operation := func() error {
log.Info("Checking GitLab internal API availability")
err := g.client.Status()
if err != nil {
log.WithError(err).Warn("attempted to connect to the API")
}
return err
}
err := backoff.Retry(operation, backOff)
if err != nil {
log.WithError(err).Errorf("failed to connect to the internal GitLab API after %.2fs", maxElapsedTime.Seconds())
return
}
g.mu.Lock()
g.isReady = true
g.mu.Unlock()
log.Info("GitLab internal pages status API connected successfully")
}
|