Skip to content

Commit 9dfab95

Browse files
authored
fix: scale only if check run is in statues queued. #14 (#423)
1 parent 8e39f5f commit 9dfab95

File tree

2 files changed

+9
-14
lines changed

2 files changed

+9
-14
lines changed

modules/runners/lambdas/runners/src/scale-runners/scale-up.test.ts

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ jest.mock('@octokit/auth-app', () => ({
1111
const mockOctokit = {
1212
checks: { get: jest.fn() },
1313
actions: {
14-
listWorkflowRunsForRepo: jest.fn(),
1514
createRegistrationTokenForOrg: jest.fn(),
1615
createRegistrationTokenForRepo: jest.fn(),
1716
},
@@ -40,9 +39,9 @@ describe('scaleUp', () => {
4039
process.env.ENVIRONMENT = 'unit-test-environment';
4140

4241
jest.clearAllMocks();
43-
mockOctokit.actions.listWorkflowRunsForRepo.mockImplementation(() => ({
42+
mockOctokit.checks.get.mockImplementation(() => ({
4443
data: {
45-
total_count: 1,
44+
status: 'queued',
4645
},
4746
}));
4847
const mockTokenReturnValue = {
@@ -70,16 +69,16 @@ describe('scaleUp', () => {
7069

7170
it('checks queued workflows', async () => {
7271
await scaleUp('aws:sqs', TEST_DATA);
73-
expect(mockOctokit.actions.listWorkflowRunsForRepo).toBeCalledWith({
72+
expect(mockOctokit.checks.get).toBeCalledWith({
73+
check_run_id: TEST_DATA.id,
7474
owner: TEST_DATA.repositoryOwner,
7575
repo: TEST_DATA.repositoryName,
76-
status: 'queued',
7776
});
7877
});
7978

8079
it('does not list runners when no workflows are queued', async () => {
81-
mockOctokit.actions.listWorkflowRunsForRepo.mockImplementation(() => ({
82-
data: { total_count: 0, runners: [] },
80+
mockOctokit.checks.get.mockImplementation(() => ({
81+
data: { status: 'completed' },
8382
}));
8483
await scaleUp('aws:sqs', TEST_DATA);
8584
expect(listRunners).not.toBeCalled();

modules/runners/lambdas/runners/src/scale-runners/scale-up.ts

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -56,17 +56,13 @@ export const scaleUp = async (eventSource: string, payload: ActionRequestMessage
5656
const environment = process.env.ENVIRONMENT as string;
5757
const githubAppAuth = await createGithubAppAuth(payload.installationId);
5858
const githubInstallationClient = await createInstallationClient(githubAppAuth);
59-
const queuedWorkflows = await githubInstallationClient.actions.listWorkflowRunsForRepo({
59+
const checkRun = await githubInstallationClient.checks.get({
60+
check_run_id: payload.id,
6061
owner: payload.repositoryOwner,
6162
repo: payload.repositoryName,
62-
// @ts-ignore (typing of the 'status' field is incorrect)
63-
status: 'queued',
6463
});
65-
console.info(
66-
`Repo ${payload.repositoryOwner}/${payload.repositoryName} has ${queuedWorkflows.data.total_count} queued workflow runs`,
67-
);
6864

69-
if (queuedWorkflows.data.total_count > 0) {
65+
if (checkRun.data.status === 'queued') {
7066
const currentRunners = await listRunners({
7167
environment: environment,
7268
repoName: enableOrgLevel ? undefined : `${payload.repositoryOwner}/${payload.repositoryName}`,

0 commit comments

Comments
 (0)