-
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.
Added route which runs every 15 min to process pending scans via invoke
- Loading branch information
1 parent
c30d332
commit a9516cd
Showing
5 changed files
with
57 additions
and
49 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
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 |
---|---|---|
@@ -1,7 +1,10 @@ | ||
import { runEveryMinute } from '#src/scheduled/index'; | ||
import { runEveryFifteenMinutes, runEveryMinute } from '#src/scheduled/index'; | ||
|
||
export const scheduled = async (event) => { | ||
if (event.path.endsWith('/runEveryMinute')) { | ||
return runEveryMinute(); | ||
} | ||
else if (event.path.endsWith('/runEveryFifteenMinutes')) { | ||
return runEveryFifteenMinutes(); | ||
} | ||
} |
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 +1,2 @@ | ||
export * from './runEveryMinute' | ||
export * from './runEveryMinute' | ||
export * from './runEveryFifteenMinutes' |
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,24 @@ | ||
import { db, isStaging } from '#src/utils'; | ||
import { LambdaClient, InvokeCommand } from '@aws-sdk/client-lambda'; | ||
const lambda = new LambdaClient(); | ||
|
||
export const runEveryFifteenMinutes = async () => { | ||
await db.connect(); | ||
const pendingScans = (await db.query({ | ||
text: `SELECT DISTINCT "user_id", "property_id" FROM "scans" WHERE "processing" = true`, | ||
})).rows; | ||
await db.clean(); | ||
console.log(JSON.stringify({ pendingScans })); | ||
for (const { user_id, property_id } of pendingScans) { | ||
lambda.send(new InvokeCommand({ | ||
FunctionName: `equalify-api${isStaging ? '-staging' : ''}`, | ||
InvocationType: "Event", | ||
Payload: Buffer.from(JSON.stringify({ | ||
path: '/internal/processScans', | ||
userId: user_id, | ||
propertyId: property_id, | ||
})), | ||
})); | ||
} | ||
return; | ||
} |