@@ -10,15 +10,17 @@ const sleep = (ms: number) =>
1010 setTimeout ( resolve , ms ) ;
1111 } ) ;
1212
13- export async function pollSupplierAllocatorLogForResolvedSpec (
14- domainId : string ,
13+ async function pollLambdaLog (
14+ lambdaName : string ,
15+ filterPatterns : string [ ] ,
16+ extraPatterns ?: string [ ] ,
1517) : Promise < string > {
1618 const intervalMs = 5000 ;
1719 const startTimeMs = Date . now ( ) - 5 * 60_000 ;
1820 const timeoutMs = 120_000 ;
1921
2022 const client = new CloudWatchLogsClient ( { region : AWS_REGION } ) ;
21- const logGroupName = `/aws/lambda/nhs-${ envName } -supapi-supplier-allocator ` ;
23+ const logGroupName = `/aws/lambda/nhs-${ envName } -supapi-${ lambdaName } ` ;
2224 const deadline = Date . now ( ) + timeoutMs ;
2325
2426 while ( Date . now ( ) < deadline ) {
@@ -28,18 +30,15 @@ export async function pollSupplierAllocatorLogForResolvedSpec(
2830 startTime : startTimeMs ,
2931 interleaved : true ,
3032 limit : 100 ,
31- filterPattern : `"Sending message to upsert letter queue" " ${ domainId } "` ,
33+ filterPattern : filterPatterns . join ( " " ) ,
3234 } ) ,
3335 ) ;
3436
3537 const foundEvent = ( response . events ?? [ ] ) . find ( ( event ) => {
3638 const message = event . message ?? "" ;
37- return (
38- message . includes (
39- '"description":"Sending message to upsert letter queue"' ,
40- ) &&
41- ( ! domainId || message . includes ( domainId ) )
42- ) ;
39+ return extraPatterns
40+ ? extraPatterns . some ( ( pattern ) => message . includes ( pattern ) )
41+ : true ;
4342 } ) ;
4443 if ( foundEvent ?. message ) {
4544 return foundEvent . message ;
@@ -48,55 +47,38 @@ export async function pollSupplierAllocatorLogForResolvedSpec(
4847 await sleep ( intervalMs ) ;
4948 }
5049
51- throw new Error (
52- `Timed out waiting for resolved supplier spec log in ${ logGroupName } ` ,
53- ) ;
50+ throw new Error ( `Timed out waiting for resolved log in ${ logGroupName } ` ) ;
51+ }
52+
53+ export async function pollSupplierAllocatorLogForResolvedSpec (
54+ domainId : string ,
55+ ) : Promise < string > {
56+ return pollLambdaLog ( "supplier-allocator" , [
57+ '"Sending message to upsert letter queue"' ,
58+ `"${ domainId } "` ,
59+ ] ) ;
5460}
5561
5662export async function pollUpsertLetterLogForError (
5763 msgToCheck : string ,
5864 domainId ?: string ,
5965) : Promise < string > {
60- const intervalMs = 5000 ;
61- const startTimeMs = Date . now ( ) - 5 * 60_000 ;
62- const timeoutMs = 120_000 ;
63-
64- const client = new CloudWatchLogsClient ( { region : AWS_REGION } ) ;
65- const logGroupName = `/aws/lambda/nhs-${ envName } -supapi-upsertletter` ;
66- const deadline = Date . now ( ) + timeoutMs ;
67-
68- while ( Date . now ( ) < deadline ) {
69- const response = await client . send (
70- new FilterLogEventsCommand ( {
71- logGroupName,
72- startTime : startTimeMs ,
73- interleaved : true ,
74- limit : 100 ,
75- filterPattern : domainId
76- ? `"Error processing upsert of record" "${ domainId } "`
77- : `"Error processing upsert of record"` ,
78- } ) ,
79- ) ;
80-
81- const foundEvent = ( response . events ?? [ ] ) . find ( ( event ) => {
82- const message = event . message ?? "" ;
83- return (
84- message . includes ( '"description":"Error processing upsert of record"' ) &&
85- ( message . includes ( `"message":"${ msgToCheck } ` ) ||
86- message . includes ( `"message": "${ msgToCheck } ` ) )
87- ) ;
88- } ) ;
89-
90- if ( foundEvent ?. message ) {
91- return foundEvent . message ;
92- }
93-
94- await sleep ( intervalMs ) ;
66+ const filterPatterns = [ '"Error processing upsert of record"' ] ;
67+ if ( domainId ) {
68+ filterPatterns . push ( `"${ domainId } "` ) ;
9569 }
70+ return pollLambdaLog ( "upsertletter" , filterPatterns , [
71+ `"message": "${ msgToCheck } ` ,
72+ `"message":"${ msgToCheck } ` ,
73+ ] ) ;
74+ }
9675
97- throw new Error (
98- `Timed out waiting for upsert letter error log in ${ logGroupName } ` ,
99- ) ;
76+ export async function pollUpsertLetterLogForWarning (
77+ description : string ,
78+ domainId : string ,
79+ ) : Promise < string > {
80+ const filterPatterns = [ '"WARN"' , `"${ domainId } "` , `"${ description } "` ] ;
81+ return pollLambdaLog ( "upsertletter" , filterPatterns ) ;
10082}
10183
10284export async function supplierIdFromSupplierAllocatorLog (
0 commit comments