Skip to content

Commit

Permalink
Add delay when there's an error calling github api
Browse files Browse the repository at this point in the history
  • Loading branch information
mikogs committed Nov 15, 2024
1 parent 5187660 commit d90f66a
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
6 changes: 4 additions & 2 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,9 @@ func runHandler(cli *broccli.CLI) int {
// and set prometheus' Gauge value
go func() {
for {
// flag is already validated by cli lib
sleepInt, _ := strconv.Atoi(cli.Flag("sleep"))

// We are never going to have more than 100 runners so getting page 1 only
req, err := http.NewRequest("GET", fmt.Sprintf("https://api.github.com/orgs/%s/actions/runners?per_page=100&page=1", cli.Flag("organization")), strings.NewReader(""))
if err != nil {
Expand All @@ -74,6 +77,7 @@ func runHandler(cli *broccli.CLI) int {
resp, err := c.Do(req)
if err != nil {
fmt.Fprint(os.Stderr, "!!! Error making request to GitHub API\n")
time.Sleep(time.Duration(sleepInt*10) * time.Second)
continue
}

Expand All @@ -88,8 +92,6 @@ func runHandler(cli *broccli.CLI) int {
totalCount.Set(float64(response.TotalCount))
totalCountOnline.Set(float64(response.TotalCountOnline()))

// flag is already validated by cli lib
sleepInt, _ := strconv.Atoi(cli.Flag("sleep"))
time.Sleep(time.Duration(sleepInt) * time.Second)
}
}()
Expand Down
2 changes: 1 addition & 1 deletion version.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
package main

const VERSION = "0.1.2"
const VERSION = "0.1.3"

0 comments on commit d90f66a

Please sign in to comment.