Skip to content

Commit e93cdbd

Browse files
committed
Backend: added back email processing to runsEveryMinute, typing cleanup
1 parent 2485448 commit e93cdbd

1 file changed

Lines changed: 16 additions & 6 deletions

File tree

apps/backend/routes/scheduled/runEveryMinute.ts

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,15 @@
11
import { db, graphqlQuery } from "#src/utils";
22
import { LambdaClient, InvokeCommand } from "@aws-sdk/client-lambda";
3-
import { syncAuditUrlsFromRemoteCsv } from "../internal";
3+
import {
4+
processScheduledAuditEmails,
5+
syncAuditUrlsFromRemoteCsv,
6+
} from "../internal";
47
const lambda = new LambdaClient();
58

69
export const runEveryMinute = async () => {
710
// Perform health check
811
const response = await graphqlQuery({ query: `{users(limit:1){id}}` });
9-
if (!response?.users?.[0]?.id) {
12+
if (!response?.users?.[0]?.id && process.env.SLACK_WEBHOOK) {
1013
await fetch(process.env.SLACK_WEBHOOK, {
1114
method: "POST",
1215
body: JSON.stringify({
@@ -45,9 +48,8 @@ export const runEveryMinute = async () => {
4548
)
4649
)`,
4750
})
48-
).rows.map((obj) => obj.id);
51+
).rows.map((obj: { id: string; }) => obj.id);
4952
for (const scheduledAuditId of scheduledAuditIds) {
50-
5153
// hook to check for remote CSV
5254
await syncAuditUrlsFromRemoteCsv(scheduledAuditId);
5355

@@ -70,7 +72,7 @@ export const runEveryMinute = async () => {
7072
values: [
7173
scheduledAuditId,
7274
"processing",
73-
JSON.stringify(urls.map((obj) => ({ url: obj.url, type: obj.type }))),
75+
JSON.stringify(urls.map((obj: { url: string; type: string; }) => ({ url: obj.url, type: obj.type }))),
7476
],
7577
})
7678
).rows[0].id;
@@ -79,7 +81,7 @@ export const runEveryMinute = async () => {
7981
FunctionName: "aws-lambda-scan-sqs-router",
8082
InvocationType: "Event",
8183
Payload: JSON.stringify({
82-
urls: urls?.map((url) => ({
84+
urls: urls?.map((url: { id: string; url: string; type: string; }) => ({
8385
auditId: scheduledAuditId,
8486
scanId: scanId,
8587
urlId: url.id,
@@ -140,5 +142,13 @@ export const runEveryMinute = async () => {
140142
}
141143

142144
await db.clean();
145+
146+
// Process scheduled audit email notifications
147+
try {
148+
await processScheduledAuditEmails();
149+
} catch (emailError) {
150+
console.error("Scheduled audit email processing failed:", emailError);
151+
}
152+
143153
return;
144154
};

0 commit comments

Comments
 (0)