Skip to content
This repository was archived by the owner on Jan 16, 2025. It is now read-only.

Commit 0e9b083

Browse files
ulichsamuelb
andauthored
fix: Don't delete busy runners (#1832)
* Don't attempt to delete busy runners * fix idleCounter logic * adjust tests to cover the new case * remove debugging code Co-authored-by: Samuel Barabas <[email protected]>
1 parent c17303d commit 0e9b083

File tree

2 files changed

+24
-7
lines changed

2 files changed

+24
-7
lines changed

Diff for: modules/runners/lambdas/runners/src/scale-runners/scale-down.test.ts

+21-1
Original file line numberDiff line numberDiff line change
@@ -143,32 +143,51 @@ const DEFAULT_RUNNERS_ORIGINAL = [
143143
launchTime: moment(new Date()).toDate(),
144144
repo: `${TEST_DATA.repositoryOwner}/${TEST_DATA.repositoryName}`,
145145
},
146+
{
147+
instanceId: 'i-busy-112',
148+
launchTime: moment(new Date())
149+
.subtract(minimumRunningTimeInMinutes + 27, 'minutes')
150+
.toDate(),
151+
type: 'Org',
152+
owner: TEST_DATA.repositoryOwner,
153+
},
146154
];
147155

148156
const DEFAULT_REGISTERED_RUNNERS = [
149157
{
150158
id: 101,
151159
name: 'i-idle-101',
160+
busy: false,
152161
},
153162
{
154163
id: 102,
155164
name: 'i-idle-102',
165+
busy: false,
156166
},
157167
{
158168
id: 103,
159169
name: 'i-oldest-idle-103',
170+
busy: false,
160171
},
161172
{
162173
id: 104,
163174
name: 'i-oldest-idle-104',
175+
busy: false,
164176
},
165177
{
166178
id: 105,
167179
name: 'i-running-105',
180+
busy: false,
168181
},
169182
{
170183
id: 106,
171184
name: 'i-running-106',
185+
busy: false,
186+
},
187+
{
188+
id: 112,
189+
name: 'i-busy-112',
190+
busy: true,
172191
},
173192
];
174193

@@ -260,7 +279,8 @@ describe('scaleDown', () => {
260279
);
261280

262281
RUNNERS_ALL_REMOVED = DEFAULT_RUNNERS_ORG.filter(
263-
(r) => !r.instanceId.includes('running') && !r.instanceId.includes('registered'),
282+
(r) =>
283+
!r.instanceId.includes('running') && !r.instanceId.includes('registered') && !r.instanceId.includes('busy'),
264284
);
265285
DEFAULT_RUNNERS_ORPHANED = DEFAULT_RUNNERS_ORIGINAL.filter(
266286
(r) => r.instanceId.includes('orphan') && !r.instanceId.includes('not-registered'),

Diff for: modules/runners/lambdas/runners/src/scale-runners/scale-down.ts

+3-6
Original file line numberDiff line numberDiff line change
@@ -111,10 +111,7 @@ async function removeRunner(ec2runner: RunnerInfo, ghRunnerId: number): Promise<
111111
logger.error(`Failed to de-register GitHub runner: ${result.status}`, LogFields.print());
112112
}
113113
} catch (e) {
114-
logger.info(
115-
`Runner '${ec2runner.instanceId}' cannot be de-registered, most likely the runner is active.`,
116-
LogFields.print(),
117-
);
114+
logger.error(`Runner '${ec2runner.instanceId}' cannot be de-registered. Error: ${e}`, LogFields.print());
118115
}
119116
}
120117

@@ -135,10 +132,10 @@ async function evaluateAndRemoveRunners(
135132
const ghRunners = await listGitHubRunners(ec2Runner);
136133
const ghRunner = ghRunners.find((runner) => runner.name === ec2Runner.instanceId);
137134
if (ghRunner) {
138-
if (runnerMinimumTimeExceeded(ec2Runner)) {
135+
if (!ghRunner.busy && runnerMinimumTimeExceeded(ec2Runner)) {
139136
if (idleCounter > 0) {
140137
idleCounter--;
141-
logger.info(`Runner '${ec2Runner.instanceId}' will kept idle.`, LogFields.print());
138+
logger.info(`Runner '${ec2Runner.instanceId}' will be kept idle.`, LogFields.print());
142139
} else {
143140
logger.info(`Runner '${ec2Runner.instanceId}' will be terminated.`, LogFields.print());
144141
await removeRunner(ec2Runner, ghRunner.id);

0 commit comments

Comments
 (0)