Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab_poll.go « gitlab « source « internal - gitlab.com/gitlab-org/gitlab-pages.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 0284449a7e6807e49312f518fad5884d5851aa6d (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
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")

		return g.client.Status()
	}

	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")
}