From f61d3a09a8d0bc6aafe529f702ef77e4907ba981 Mon Sep 17 00:00:00 2001 From: azdak Date: Tue, 19 Nov 2024 20:11:32 -0600 Subject: [PATCH] Exposed pollOutstandingScan as endpoint for testing --- src/app.ts | 4 ++++ src/internal/pollOutstandingScans.ts | 6 ++++-- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/src/app.ts b/src/app.ts index 49b19b4..6024651 100644 --- a/src/app.ts +++ b/src/app.ts @@ -3,6 +3,7 @@ import { addPages, getScan, addProperties, addReports, addResults, addScans, del import { CognitoJwtVerifier } from 'aws-jwt-verify'; import { db } from './utils'; import { suggestIssue } from './routes/suggestIssue'; +import { pollOutstandingScans } from './internal'; export const fastify = Fastify(); const cognitoJwtVerifier = CognitoJwtVerifier.create({ @@ -70,6 +71,9 @@ fastify.post('/help', {}, async (request, reply) => help({ request, reply })); fastify.post('/track/user', {}, async (request, reply) => trackUser({ request, reply })); fastify.post('/ai/suggest-issue', {}, async (request, reply) => suggestIssue({ request, reply })); +// TESTING requests +fastify.post('/testing/pollOutstandingScans', {}, (request, reply) => pollOutstandingScans({ request, reply })); + fastify.listen({ port: 3000 }, (err) => { console.log(`Server listening on ${fastify.server.address().port}`) if (err) throw err diff --git a/src/internal/pollOutstandingScans.ts b/src/internal/pollOutstandingScans.ts index c182784..8c4bef1 100644 --- a/src/internal/pollOutstandingScans.ts +++ b/src/internal/pollOutstandingScans.ts @@ -1,5 +1,5 @@ import { chunk, db, isStaging, sleep, hashStringToUuid } from '#src/utils'; -export const pollOutstandingScans = async () => { +export const pollOutstandingScans = async ({ request, reply }) => { console.log(`START POLLING OPEN SCANS`); const startTime = new Date().getTime(); const jobIds = (await db.query({ @@ -8,5 +8,7 @@ export const pollOutstandingScans = async () => { await db.clean(); const deltaTime = new Date().getTime() - startTime; console.log(`END PROCESS SCANS, took ${deltaTime}`); - return; + return { + jobIds + }; } \ No newline at end of file