From 84089c3c46252c9266fce293882e6ad2b511c7a1 Mon Sep 17 00:00:00 2001 From: Nathaniel McAuliffe Date: Tue, 7 Sep 2021 12:49:45 -0400 Subject: [PATCH 1/2] fix(scale-down): Clearing cache between runs --- modules/runners/lambdas/runners/src/scale-runners/cache.ts | 5 +++++ .../runners/lambdas/runners/src/scale-runners/scale-down.ts | 4 ++++ 2 files changed, 9 insertions(+) diff --git a/modules/runners/lambdas/runners/src/scale-runners/cache.ts b/modules/runners/lambdas/runners/src/scale-runners/cache.ts index 8c0c34a14a..302a24b2d5 100644 --- a/modules/runners/lambdas/runners/src/scale-runners/cache.ts +++ b/modules/runners/lambdas/runners/src/scale-runners/cache.ts @@ -7,4 +7,9 @@ export type GhRunners = UnboxPromise = new Map(); static runners: Map = new Map(); + + public static reset(): void { + githubCache.clients.clear(); + githubCache.runners.clear(); + } } diff --git a/modules/runners/lambdas/runners/src/scale-runners/scale-down.ts b/modules/runners/lambdas/runners/src/scale-runners/scale-down.ts index f05c8317e0..b75175d0b8 100644 --- a/modules/runners/lambdas/runners/src/scale-runners/scale-down.ts +++ b/modules/runners/lambdas/runners/src/scale-runners/scale-down.ts @@ -57,10 +57,12 @@ async function listGitHubRunners(runner: RunnerInfo): Promise { runner.type === 'Org' ? await client.paginate(client.actions.listSelfHostedRunnersForOrg, { org: runner.owner, + per_page: 100, }) : await client.paginate(client.actions.listSelfHostedRunnersForRepo, { owner: runner.owner.split('/')[0], repo: runner.owner.split('/')[1], + per_page: 100, }); githubCache.runners.set(key, runners); @@ -117,6 +119,7 @@ async function evaluateAndRemoveRunners( const ec2RunnersFiltered = ec2Runners.filter((runner) => runner.owner === ownerTag); for (const ec2Runner of ec2RunnersFiltered) { const ghRunners = await listGitHubRunners(ec2Runner); + console.debug(ghRunners); const ghRunner = ghRunners.find((runner) => runner.name === ec2Runner.instanceId); if (ghRunner) { if (runnerMinimumTimeExceeded(ec2Runner)) { @@ -182,6 +185,7 @@ function filterRunners(ec2runners: RunnerList[]): RunnerInfo[] { } export async function scaleDown(): Promise { + githubCache.reset(); const scaleDownConfigs = JSON.parse(process.env.SCALE_DOWN_CONFIG) as [ScalingDownConfig]; const environment = process.env.ENVIRONMENT; From fa4b69a41700fff9688e12d7934b1458d6a299fd Mon Sep 17 00:00:00 2001 From: Nathaniel McAuliffe Date: Tue, 7 Sep 2021 12:51:16 -0400 Subject: [PATCH 2/2] Removing debug statement --- modules/runners/lambdas/runners/src/scale-runners/scale-down.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/modules/runners/lambdas/runners/src/scale-runners/scale-down.ts b/modules/runners/lambdas/runners/src/scale-runners/scale-down.ts index b75175d0b8..f96df1893b 100644 --- a/modules/runners/lambdas/runners/src/scale-runners/scale-down.ts +++ b/modules/runners/lambdas/runners/src/scale-runners/scale-down.ts @@ -119,7 +119,6 @@ async function evaluateAndRemoveRunners( const ec2RunnersFiltered = ec2Runners.filter((runner) => runner.owner === ownerTag); for (const ec2Runner of ec2RunnersFiltered) { const ghRunners = await listGitHubRunners(ec2Runner); - console.debug(ghRunners); const ghRunner = ghRunners.find((runner) => runner.name === ec2Runner.instanceId); if (ghRunner) { if (runnerMinimumTimeExceeded(ec2Runner)) {