-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Starting scans, storing jobId, polling for finished jobs w/ processScans
- Loading branch information
1 parent
4920e85
commit 39e9108
Showing
6 changed files
with
42 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,15 @@ | ||
import awsLambdaFastify from "@fastify/aws-lambda"; | ||
import { fastify } from "./app.js"; | ||
import { cognito } from './cognito.js'; | ||
import { scheduled } from './scheduled.js'; | ||
const proxy = awsLambdaFastify(fastify); | ||
|
||
export async function handler(event: any, context: any) { | ||
if (event.triggerSource) { | ||
return await cognito(event); | ||
} | ||
else if (event.internalPath?.startsWith('/scheduled')) { | ||
return await scheduled(event); | ||
} | ||
return await proxy(event, context); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import { processScans } from './scheduled/index.js'; | ||
|
||
export const scheduled = async (event) => { | ||
if (event.internalPath.endsWith('/processScans')) { | ||
return processScans(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export * from './processScans' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import { pgClient } from 'utils'; | ||
|
||
export const processScans = async () => { | ||
await pgClient.connect(); | ||
const scans = (await pgClient.query(`SELECT "id", "job_id" FROM "scans" WHERE "processing"=TRUE ORDER BY "created_at" DESC`)).rows; | ||
for (const scan of scans) { | ||
const response = await (await fetch(`https://scan.equalify.app/results/${scan.job_id}`)).json(); | ||
if (response?.status === 'completed') { | ||
await pgClient.query(`UPDATE "scans" SET "processing"=FALSE, "results"=$1`, [response?.result]); | ||
} | ||
} | ||
await pgClient.clean(); | ||
return; | ||
} |