diff --git a/modules/runners/lambdas/runners/src/lambda.test.ts b/modules/runners/lambdas/runners/src/lambda.test.ts index f77cfac0b1..43f5ffdff3 100644 --- a/modules/runners/lambdas/runners/src/lambda.test.ts +++ b/modules/runners/lambdas/runners/src/lambda.test.ts @@ -112,6 +112,7 @@ async function testInvalidRecords(sqsRecords: SQSRecord[]) { expect(logWarnSpy).toHaveBeenCalledWith( 'Event ignored, only one record at the time can be handled, ensure the lambda batch size is set to 1.', + undefined, ); } diff --git a/modules/runners/lambdas/runners/src/lambda.ts b/modules/runners/lambdas/runners/src/lambda.ts index 183f0ac502..20e1c40135 100644 --- a/modules/runners/lambdas/runners/src/lambda.ts +++ b/modules/runners/lambdas/runners/src/lambda.ts @@ -1,7 +1,7 @@ import { scaleUp } from './scale-runners/scale-up'; import { scaleDown } from './scale-runners/scale-down'; import { SQSEvent, ScheduledEvent, Context, Callback } from 'aws-lambda'; -import { logger } from './scale-runners/logger'; +import { LogFields, logger } from './scale-runners/logger'; import ScaleError from './scale-runners/ScaleError'; import 'source-map-support/register'; @@ -9,32 +9,30 @@ export async function scaleUpHandler(event: SQSEvent, context: Context): Promise logger.setSettings({ requestId: context.awsRequestId }); logger.debug(JSON.stringify(event)); if (event.Records.length !== 1) { - logger.warn('Event ignored, only one record at the time can be handled, ensure the lambda batch size is set to 1.'); + logger.warn( + 'Event ignored, only one record at the time can be handled, ensure the lambda batch size is set to 1.', + LogFields.print(), + ); return new Promise((resolve) => resolve()); } - return new Promise((resolve, reject) => { - scaleUp(event.Records[0].eventSource, JSON.parse(event.Records[0].body)) - .then(() => resolve()) - .catch((e: Error) => { - if (e instanceof ScaleError) { - reject(e); - } else { - logger.warn(`Ignoring error: ${e.message}`); - } - }); - }); + try { + await scaleUp(event.Records[0].eventSource, JSON.parse(event.Records[0].body)); + } catch (e) { + if (e instanceof ScaleError) { + throw e; + } else { + logger.warn(`Ignoring error: ${(e as Error).message}`, LogFields.print()); + } + } } export async function scaleDownHandler(event: ScheduledEvent, context: Context): Promise { logger.setSettings({ requestId: context.awsRequestId }); - return new Promise((resolve) => { - scaleDown() - .then(() => resolve()) - .catch((e) => { - logger.error(e); - resolve(); - }); - }); + try { + await scaleDown(); + } catch (e) { + logger.error(e); + } } diff --git a/modules/runners/lambdas/runners/src/scale-runners/scale-up.ts b/modules/runners/lambdas/runners/src/scale-runners/scale-up.ts index 6eca9b43b2..8422c09540 100644 --- a/modules/runners/lambdas/runners/src/scale-runners/scale-up.ts +++ b/modules/runners/lambdas/runners/src/scale-runners/scale-up.ts @@ -16,7 +16,10 @@ export interface ActionRequestMessage { } export async function scaleUp(eventSource: string, payload: ActionRequestMessage): Promise { - logger.info(`Received ${payload.eventType} from ${payload.repositoryOwner}/${payload.repositoryName}`); + logger.info( + `Received ${payload.eventType} from ${payload.repositoryOwner}/${payload.repositoryName}`, + LogFields.print(), + ); if (eventSource !== 'aws:sqs') throw Error('Cannot handle non-SQS events!'); const enableOrgLevel = yn(process.env.ENABLE_ORGANIZATION_RUNNERS, { default: true }); @@ -28,7 +31,10 @@ export async function scaleUp(eventSource: string, payload: ActionRequestMessage const ephemeralEnabled = yn(process.env.ENABLE_EPHEMERAL_RUNNERS, { default: false }); if (ephemeralEnabled && payload.eventType !== 'workflow_job') { - logger.warn(`${payload.eventType} event is not supported in combination with ephemeral runners.`); + logger.warn( + `${payload.eventType} event is not supported in combination with ephemeral runners.`, + LogFields.print(), + ); throw Error( `The event type ${payload.eventType} is not supported in combination with ephemeral runners.` + `Please ensure you have enabled workflow_job events.`,