diff --git a/api/handlers/jobs.ts b/api/handlers/jobs.ts index 8aedd6ffd..2f0bfe9ca 100644 --- a/api/handlers/jobs.ts +++ b/api/handlers/jobs.ts @@ -246,10 +246,20 @@ export async function snootyBuildComplete(event: APIGatewayEvent): Promise('dbName')); const jobRepository = new JobRepository(db, c, consoleLogger); - await jobRepository.updateExecutionTime(jobId, { gatsbyCloudEndTime: new Date() }); - const updateResponse = await jobRepository.updateWithStatus(jobId, null, payload.status || JobStatus.failed, false); - const previewUrl = getPreviewUrl(updateResponse.payload, c.get('env')); - await notifyBuildSummary(jobId, { mongoClient: client, previewUrl }); + + if (event.queryStringParameters?.builder === 'netlify') { + await jobRepository.updateExecutionTime(jobId, { netlifyEndTime: new Date() }); + } else { + await jobRepository.updateExecutionTime(jobId, { gatsbyCloudEndTime: new Date() }); + const updateResponse = await jobRepository.updateWithStatus( + jobId, + null, + payload.status || JobStatus.failed, + false + ); + const previewUrl = getPreviewUrl(updateResponse.payload, c.get('env')); + await notifyBuildSummary(jobId, { mongoClient: client, previewUrl }); + } } catch (e) { consoleLogger.error('SnootyBuildCompleteError', e); return { diff --git a/src/repositories/jobRepository.ts b/src/repositories/jobRepository.ts index ba4caa83c..7712f15b3 100644 --- a/src/repositories/jobRepository.ts +++ b/src/repositories/jobRepository.ts @@ -106,9 +106,11 @@ export class JobRepository extends BaseRepository { _id: new objectId(id), }; const update = { $set: setValues }; - this.updateOne(query, update, `Mongo Timeout Error: Timed out while retrieving job`).catch((err) => { + try { + await this.updateOne(query, update, `Mongo Timeout Error: Timed out while retrieving job`); + } catch (err) { this._logger.error('updateExecutionTime', `Error: ${err}`); - }); + } } async findOneAndUpdateJob(query): Promise { diff --git a/tests/unit/job/api/jobs.test.ts b/tests/unit/job/api/jobs.test.ts index c88acca6b..0d834ea4c 100644 --- a/tests/unit/job/api/jobs.test.ts +++ b/tests/unit/job/api/jobs.test.ts @@ -77,4 +77,15 @@ describe('Post-build webhook tests', () => { ); expect(res.statusCode).toBe(400); }); + + test('successfully handles builder=netlify query string param', async () => { + const signature = createSha256Signature(payloadString, 'SNOOTY_SECRET'); + const mockReqEvent = createMockAPIGatewayEvent(payloadString, { 'x-snooty-signature': signature }); + mockReqEvent.queryStringParameters = { + builder: 'netlify', + }; + const res = await SnootyBuildComplete(mockReqEvent); + // Ideally, we would have a more robust way to check that only specific data is updated + expect(res.statusCode).toBe(200); + }); });