@@ -50,48 +50,53 @@ export const runEveryMinute = async () => {
5050 } )
5151 ) . rows . map ( ( obj : { id : string ; } ) => obj . id ) ;
5252 for ( const scheduledAuditId of scheduledAuditIds ) {
53- // hook to check for remote CSV
54- await syncAuditUrlsFromRemoteCsv ( scheduledAuditId ) ;
53+ // isolate each audit so one failure can't starve the rest of the batch
54+ try {
55+ // hook to check for remote CSV
56+ await syncAuditUrlsFromRemoteCsv ( scheduledAuditId ) ;
5557
56- const urls = (
57- await db . query ( {
58- text : `SELECT * FROM "urls" WHERE "audit_id"=$1` ,
59- values : [ scheduledAuditId ] ,
60- } )
61- ) . rows ;
58+ const urls = (
59+ await db . query ( {
60+ text : `SELECT * FROM "urls" WHERE "audit_id"=$1` ,
61+ values : [ scheduledAuditId ] ,
62+ } )
63+ ) . rows ;
6264
63- // Skip scheduled audits with no URLs to prevent hung scans
64- if ( ! urls || urls . length === 0 ) {
65- console . log ( "Skipping scheduled audit with no URLs:" , scheduledAuditId ) ;
66- continue ;
67- }
65+ // Skip scheduled audits with no URLs to prevent hung scans
66+ if ( ! urls || urls . length === 0 ) {
67+ console . log ( "Skipping scheduled audit with no URLs:" , scheduledAuditId ) ;
68+ continue ;
69+ }
6870
69- const scanId = (
70- await db . query ( {
71- text : `INSERT INTO "scans" ("audit_id", "status", "pages") VALUES ($1, $2, $3) RETURNING "id"` ,
72- values : [
73- scheduledAuditId ,
74- "processing" ,
75- JSON . stringify ( urls . map ( ( obj : { url : string ; type : string ; } ) => ( { url : obj . url , type : obj . type } ) ) ) ,
76- ] ,
77- } )
78- ) . rows [ 0 ] . id ;
79- await lambda . send (
80- new InvokeCommand ( {
81- FunctionName : process . env . SQS_ROUTER_FUNCTION_NAME ?? "aws-lambda-scan-sqs-router" ,
82- InvocationType : "Event" ,
83- Payload : JSON . stringify ( {
84- urls : urls ?. map ( ( url : { id : string ; url : string ; type : string ; } ) => ( {
85- auditId : scheduledAuditId ,
86- scanId : scanId ,
87- urlId : url . id ,
88- url : url . url ,
89- type : url . type ,
90- } ) ) ,
71+ const scanId = (
72+ await db . query ( {
73+ text : `INSERT INTO "scans" ("audit_id", "status", "pages") VALUES ($1, $2, $3) RETURNING "id"` ,
74+ values : [
75+ scheduledAuditId ,
76+ "processing" ,
77+ JSON . stringify ( urls . map ( ( obj : { url : string ; type : string ; } ) => ( { url : obj . url , type : obj . type } ) ) ) ,
78+ ] ,
79+ } )
80+ ) . rows [ 0 ] . id ;
81+ await lambda . send (
82+ new InvokeCommand ( {
83+ FunctionName : process . env . SQS_ROUTER_FUNCTION_NAME ?? "aws-lambda-scan-sqs-router" ,
84+ InvocationType : "Event" ,
85+ Payload : JSON . stringify ( {
86+ urls : urls ?. map ( ( url : { id : string ; url : string ; type : string ; } ) => ( {
87+ auditId : scheduledAuditId ,
88+ scanId : scanId ,
89+ urlId : url . id ,
90+ url : url . url ,
91+ type : url . type ,
92+ } ) ) ,
93+ } ) ,
9194 } ) ,
92- } ) ,
93- ) ;
94- console . log ( "Scan jobs queued for audit:" , scheduledAuditId ) ;
95+ ) ;
96+ console . log ( "Scan jobs queued for audit:" , scheduledAuditId ) ;
97+ } catch ( error ) {
98+ console . error ( "Scheduled scan failed for audit:" , scheduledAuditId , error ) ;
99+ }
95100 }
96101
97102 // See if there are any "stuck" scans that we should error out!
0 commit comments