Skip to content

Commit

Permalink
Immediately starting processScans if property is single, otherwise queue
Browse files Browse the repository at this point in the history
  • Loading branch information
heythisischris committed Sep 6, 2024
1 parent 59cc33c commit f7b73b7
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 13 deletions.
6 changes: 3 additions & 3 deletions src/internal/processScans.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ export const processScans = async (event) => {
console.log(`START PROCESS SCANS`);
const startTime = new Date().getTime();
await db.connect();
const { userId, propertyId } = event;
const { userId, propertyId, discovery } = event;
const jobIds = (await db.query({
text: `SELECT "job_id" FROM "scans" WHERE "user_id"=$1 AND "property_id"=$2 AND "processing" = TRUE`,
values: [userId, propertyId],
text: `SELECT s.job_id FROM scans as s INNER JOIN properties AS p ON s.property_id = p.id WHERE s.user_id=$1 AND s.property_id=$2 AND s.processing = TRUE AND p.discovery=$3`,
values: [userId, propertyId, discovery],
})).rows.map(obj => obj.job_id);
const allNodeIds = [];
const pollScans = (givenJobIds) => new Promise(async (finalRes) => {
Expand Down
24 changes: 14 additions & 10 deletions src/routes/addScans.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export const addScans = async ({ request, reply }) => {
if (!property.discovery) {
return {
status: 'error',
message: 'One or more of the provided propertyIds is invalid',
message: 'You must provide a property discovery attribute, either "single" or "sitemap"',
}
}
try {
Expand Down Expand Up @@ -54,20 +54,24 @@ export const addScans = async ({ request, reply }) => {
values: [jwtClaims.sub, propertyId, urlId, parseInt(jobId)]
})).rows[0];
}

if (property.discovery === 'single') {
lambda.send(new InvokeCommand({
FunctionName: `equalify-api${isStaging ? '-staging' : ''}`,
InvocationType: "Event",
Payload: Buffer.from(JSON.stringify({
path: '/internal/processScans',
userId: jwtClaims.sub,
propertyId: propertyId,
discovery: 'single',
})),
}));
}
}
}
catch (err) {
console.log(err);
}
// lambda.send(new InvokeCommand({
// FunctionName: `equalify-api${isStaging ? '-staging' : ''}`,
// InvocationType: "Event",
// Payload: Buffer.from(JSON.stringify({
// path: '/internal/processScans',
// userId: jwtClaims.sub,
// propertyId: propertyId,
// })),
// }));
}
await db.clean();

Expand Down
1 change: 1 addition & 0 deletions src/scheduled/runEveryFifteenMinutes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ export const runEveryFifteenMinutes = async () => {
path: '/internal/processScans',
userId: user_id,
propertyId: property_id,
discovery: 'sitemap',
})),
}));
}
Expand Down

0 comments on commit f7b73b7

Please sign in to comment.