From 4eb8d905ab3fa5426ad1465bc12f6865f8d323df Mon Sep 17 00:00:00 2001 From: Michael Kuhnt Date: Tue, 31 Jan 2023 16:26:38 +0100 Subject: [PATCH] fix: skip spawn new runners if enough idle runner available --- runner/pool/pool.go | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/runner/pool/pool.go b/runner/pool/pool.go index 437b3d7b..26553ffa 100644 --- a/runner/pool/pool.go +++ b/runner/pool/pool.go @@ -381,6 +381,24 @@ func (r *basePoolManager) acquireNewInstance(job params.WorkflowJob) error { return nil } + instances, err := r.store.ListPoolInstances(r.ctx, pool.ID) + if err != nil { + return errors.Wrap(err, "fetching instances") + } + + idleWorkers := 0 + for _, inst := range instances { + if providerCommon.RunnerStatus(inst.RunnerStatus) == providerCommon.RunnerIdle && + providerCommon.InstanceStatus(inst.Status) == providerCommon.InstanceRunning { + idleWorkers++ + } + } + + if int64(idleWorkers) >= int64(pool.MinIdleRunners) { + log.Printf("we have enough min_idle_runners (%d) for pool %s, skipping...", pool.MinIdleRunners, pool.ID) + return nil + } + if err := r.AddRunner(r.ctx, pool.ID); err != nil { log.Printf("failed to add runner to pool %s", pool.ID) return errors.Wrap(err, "adding runner")