fix: remove callbacks resulting in scales due to incomplete response (#2671)

Co-authored-by: Yusuke Kuoka <ykuoka@gmail.com>
This commit is contained in:
Lars Lange
2023-07-25 02:04:54 +02:00
committed by GitHub
parent 5271f316e6
commit 297442975e
2 changed files with 71 additions and 19 deletions

View File

@@ -118,10 +118,10 @@ func (r *HorizontalRunnerAutoscalerReconciler) suggestReplicasByQueuedAndInProgr
}
var total, inProgress, queued, completed, unknown int
type callback func()
listWorkflowJobs := func(user string, repoName string, runID int64, fallback_cb callback) {
listWorkflowJobs := func(user string, repoName string, runID int64) {
if runID == 0 {
fallback_cb()
// should not happen in reality
r.Log.Info("Detected run with no runID of 0, ignoring the case and not scaling.", "repo_name", repoName, "run_id", runID)
return
}
opt := github.ListWorkflowJobsOptions{ListOptions: github.ListOptions{PerPage: 50}}
@@ -139,7 +139,8 @@ func (r *HorizontalRunnerAutoscalerReconciler) suggestReplicasByQueuedAndInProgr
opt.Page = resp.NextPage
}
if len(allJobs) == 0 {
fallback_cb()
// GitHub API can return run with empty job array - should be ignored
r.Log.Info("Detected run with no jobs, ignoring the case and not scaling.", "repo_name", repoName, "run_id", runID)
} else {
JOB:
for _, job := range allJobs {
@@ -201,9 +202,9 @@ func (r *HorizontalRunnerAutoscalerReconciler) suggestReplicasByQueuedAndInProgr
case "completed":
completed++
case "in_progress":
listWorkflowJobs(user, repoName, run.GetID(), func() { inProgress++ })
listWorkflowJobs(user, repoName, run.GetID())
case "queued":
listWorkflowJobs(user, repoName, run.GetID(), func() { queued++ })
listWorkflowJobs(user, repoName, run.GetID())
default:
unknown++
}