Skip to content

Commit

Permalink
feat: Remove old scale down mechanism (< 0.19.0) (#2519)
Browse files Browse the repository at this point in the history
fix: Remove old cleanup mechanism (< 0.19.0)
  • Loading branch information
npalm committed Oct 18, 2022
1 parent 272a293 commit 721d7c3
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -444,7 +444,7 @@ describe('scaleDown', () => {

expect(mockOctokit.apps.getRepoInstallation).toBeCalledTimes(2);
expect(mockOctokit.apps.getOrgInstallation).toBeCalledTimes(1);
expect(terminateRunner).toBeCalledTimes(8);
expect(terminateRunner).toBeCalledTimes(7);
for (const toTerminate of RUNNERS_ALL_REMOVED) {
expect(terminateRunner).toHaveBeenCalledWith(toTerminate.instanceId);
}
Expand Down Expand Up @@ -558,7 +558,7 @@ describe('scaleDown', () => {

expect(mockOctokit.apps.getRepoInstallation).toBeCalledTimes(2);
expect(mockOctokit.apps.getOrgInstallation).toBeCalledTimes(1);
expect(terminateRunner).toBeCalledTimes(8);
expect(terminateRunner).toBeCalledTimes(7);
for (const toTerminate of RUNNERS_ALL_REMOVED) {
expect(terminateRunner).toHaveBeenCalledWith(toTerminate.instanceId);
}
Expand Down
20 changes: 1 addition & 19 deletions modules/runners/lambdas/runners/src/scale-runners/scale-down.ts
Original file line number Diff line number Diff line change
Expand Up @@ -220,21 +220,6 @@ async function listAndSortRunners(environment: string) {
});
}

/**
* We are moving to a new strategy to find and remove runners, this function will ensure
* during migration runners tagged in the old way are removed.
*/
function filterLegacyRunners(ec2runners: RunnerList[]): RunnerInfo[] {
return ec2runners
.filter((ec2Runner) => ec2Runner.repo || ec2Runner.org)
.map((ec2Runner) => ({
instanceId: ec2Runner.instanceId,
launchTime: ec2Runner.launchTime,
type: ec2Runner.org ? 'Org' : 'Repo',
owner: ec2Runner.org ? (ec2Runner.org as string) : (ec2Runner.repo as string),
}));
}

function filterRunners(ec2runners: RunnerList[]): RunnerInfo[] {
return ec2runners.filter((ec2Runner) => ec2Runner.type) as RunnerInfo[];
}
Expand All @@ -256,12 +241,9 @@ export async function scaleDown(): Promise<void> {
logger.debug(`No active runners found for environment: '${environment}'`, LogFields.print());
return;
}
const legacyRunners = filterLegacyRunners(ec2Runners);
logger.debug(JSON.stringify(legacyRunners), LogFields.print());
const runners = filterRunners(ec2Runners);

const runners = filterRunners(ec2Runners);
await evaluateAndRemoveRunners(runners, scaleDownConfigs);
await evaluateAndRemoveRunners(legacyRunners, scaleDownConfigs);

const activeEc2RunnersCountAfter = (await listAndSortRunners(environment)).length;
logger.info(
Expand Down

0 comments on commit 721d7c3

Please sign in to comment.