Skip to content

Commit

Permalink
Add runs-on-high api
Browse files Browse the repository at this point in the history
Signed-off-by: Tamal Saha <[email protected]>
  • Loading branch information
tamalsaha committed Oct 5, 2023
1 parent 2c5fbc5 commit fdfe1b4
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
11 changes: 10 additions & 1 deletion pkg/backend/processor.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ func SubmitPayload(gh *github.Client, nc *nats.Conn, r *http.Request, secretToke
return nil
}

func DefaultJobLabel(gh *github.Client, org string, private bool) string {
func UseRegularRunner(gh *github.Client, org string, private bool) string {
initCache(gh)

if private && mustUsedUpFreeMinutes(actionsBillingCache.Get(org)) {
Expand All @@ -121,6 +121,15 @@ func DefaultJobLabel(gh *github.Client, org string, private bool) string {
return "ubuntu-20.04"
}

func UseHighPriorityRunner(gh *github.Client, org string, private bool) string {
initCache(gh)

if private && mustUsedUpFreeMinutes(actionsBillingCache.Get(org)) {
return RunnerHigh
}
return "ubuntu-20.04"
}

func usedUpFreeMinutes(gh *github.Client, org string) (bool, error) {
ab, _, err := gh.Billing.GetActionsBillingOrg(context.Background(), org)
if err != nil {
Expand Down
8 changes: 7 additions & 1 deletion pkg/cmds/webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,13 @@ func runServer(gh *github.Client, nc *nats.Conn, sp *backend.StatusReporter) err
r.Get("/runs-on/{org}", func(w http.ResponseWriter, r *http.Request) {
org := chi.URLParam(r, "org")
private := r.URL.Query().Get("visibility") == "private"
label := backend.DefaultJobLabel(gh, org, private)
label := backend.UseRegularRunner(gh, org, private)
_, _ = w.Write([]byte(label))
})
r.Get("/runs-on-high/{org}", func(w http.ResponseWriter, r *http.Request) {
org := chi.URLParam(r, "org")
private := r.URL.Query().Get("visibility") == "private"
label := backend.UseHighPriorityRunner(gh, org, private)
_, _ = w.Write([]byte(label))
})

Expand Down

0 comments on commit fdfe1b4

Please sign in to comment.