11import { LetterBase , LetterRepository } from "@internal/datastore" ;
22import { getSignedUrl } from "@aws-sdk/s3-request-presigner" ;
33import { GetObjectCommand , S3Client } from "@aws-sdk/client-s3" ;
4- import { SendMessageBatchCommand } from "@aws-sdk/client-sqs" ;
4+ import { MessageSystemAttributeNameForSends , SendMessageBatchCommand } from "@aws-sdk/client-sqs" ;
55import NotFoundError from "../errors/not-found-error" ;
66import { UpdateLetterCommand } from "../contracts/letters" ;
77import { ApiErrorDetail } from "../contracts/errors" ;
@@ -95,18 +95,19 @@ export async function enqueueLetterUpdateRequests(
9595 updateLetterCommands : UpdateLetterCommand [ ] ,
9696 correlationId : string ,
9797 deps : Deps ,
98- ) {
98+ ) : Promise < string [ ] > {
9999 const BATCH_SIZE = 10 ; // SQS SendMessageBatch max
100100 const CONCURRENCY = 5 ; // number of parallel batch API calls
101101
102102 const batches = chunk ( updateLetterCommands , BATCH_SIZE ) ;
103103
104104 // send batches in groups with limited concurrency
105105 // BATCH_SIZE * CONCURRENCY is the number of total updates / db calls in-flight
106+ const messageIds : string [ ] = [ ] ;
106107 for ( let i = 0 ; i < batches . length ; i += CONCURRENCY ) {
107108 const window = batches . slice ( i , i + CONCURRENCY ) ;
108109
109- await Promise . all (
110+ const batchMessageIds : string [ ] [ ] = await Promise . all (
110111 window . map ( async ( batch , batchIdx ) => {
111112 const entries = batch . map ( ( request , idx ) => ( {
112113 Id : `${ i + batchIdx } -${ idx } ` , // unique per batch entry
@@ -130,14 +131,18 @@ export async function enqueueLetterUpdateRequests(
130131 correlationId,
131132 } ) ;
132133 }
134+ return ( result . Successful || [ ] ) . map ( ( message ) => message . Id ) ;
133135 } catch ( error ) {
134136 deps . logger . error ( {
135137 err : error ,
136138 description : "Error enqueuing letter status updates" ,
137139 correlationId,
138140 } ) ;
141+ return [ ] ;
139142 }
140143 } ) ,
141144 ) ;
145+ messageIds . push ( ...batchMessageIds . flat ( ) ) ;
142146 }
147+ return messageIds ;
143148}
0 commit comments