File tree Expand file tree Collapse file tree 1 file changed +13
-9
lines changed Expand file tree Collapse file tree 1 file changed +13
-9
lines changed Original file line number Diff line number Diff line change @@ -44,6 +44,7 @@ export function createMessage<QueueUrl extends string, Shape extends ZodRawShape
44
44
}
45
45
46
46
const sendAll : BatchSend < Shape , MetadataShape > = async ( contentArray , metadata ) => {
47
+ const batches : { Id : string , MessageBody : string } [ ] [ ] = [ ] ;
47
48
for ( let i = 0 ; i < contentArray . length ; i += 10 ) {
48
49
const contentBatch = contentArray . slice ( i , i + 10 ) ;
49
50
const Entries = contentBatch . map ( content => JSON . stringify ( messageSchema . parse ( { content, metadata } ) ) )
@@ -52,15 +53,18 @@ export function createMessage<QueueUrl extends string, Shape extends ZodRawShape
52
53
MessageBody
53
54
} ) ) ;
54
55
console . log ( "sending batch" , Entries ) ;
55
- try {
56
- await sqs . sendMessageBatch ( {
57
- QueueUrl : queueUrl ,
58
- Entries
59
- } ) . promise ( ) ;
60
- } catch ( error ) {
61
- console . error ( error ) ;
62
- }
56
+ batches . push ( Entries ) ;
63
57
}
58
+ const result = await Promise . allSettled ( batches . map ( batch => sqs . sendMessageBatch ( {
59
+ QueueUrl : queueUrl ,
60
+ Entries : batch ,
61
+ } ) . promise ( ) ) ) ;
62
+
63
+ result . forEach ( ( r , i ) => {
64
+ if ( r . status === 'rejected' ) {
65
+ console . error ( 'batch failed' , r . reason , batches [ i ] ) ;
66
+ }
67
+ } ) ;
64
68
65
69
}
66
70
@@ -107,4 +111,4 @@ export function QueueHandler<Shape extends ZodRawShape, MetadataShape extends Zo
107
111
await cb ( parsed ) ;
108
112
}
109
113
}
110
- }
114
+ }
You can’t perform that action at this time.
0 commit comments