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: 9fce7250c9f5cee8ac9a2b6e65404b79fc079309 (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
package gitlab

import (
	"time"

	log "github.com/sirupsen/logrus"
)

const (
	// defaultPollingMaxRetries to be used by poll
	defaultPollingMaxRetries = 30
	// defaultPollingInterval to be used by poll
	defaultPollingInterval = time.Minute
)

// poll tries to call the /internal/pages/status API endpoint once plus
// `retries` every `interval`.
// It updates the `isReady` value when successful.
// TODO: Remove in https://gitlab.com/gitlab-org/gitlab/-/issues/218357
func (g *Gitlab) poll(retries int, interval time.Duration) {
	var err error
	for i := 0; i <= retries; i++ {
		log.Info("Checking GitLab internal API availability")
		err = g.client.Status()
		if err == nil {
			log.Info("GitLab internal pages status API connected successfully")
			g.mu.Lock()
			g.isReady = true
			g.mu.Unlock()

			// return as soon as we connect to the API
			return
		}

		time.Sleep(interval)
	}

	log.WithError(err).Errorf("Failed to connect to the internal GitLab API after %d tries every %.2fs", retries+1, interval.Seconds())
}