Skip to content

Commit 21415ef

Browse files
-> Promise.allSettled <- (#100)
* Promise.allSettled * removed imports --------- Co-authored-by: Dejan Tot <139872861+dejan-crocoder@users.noreply.github.com>
1 parent e9de34f commit 21415ef

File tree

1 file changed

+13
-9
lines changed

1 file changed

+13
-9
lines changed

apps/extract-stack/src/create-message.ts

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ export function createMessage<QueueUrl extends string, Shape extends ZodRawShape
4444
}
4545

4646
const sendAll: BatchSend<Shape, MetadataShape> = async (contentArray, metadata) => {
47+
const batches: { Id: string, MessageBody: string }[][] = [];
4748
for (let i = 0; i < contentArray.length; i += 10) {
4849
const contentBatch = contentArray.slice(i, i + 10);
4950
const Entries = contentBatch.map(content => JSON.stringify(messageSchema.parse({ content, metadata })))
@@ -52,15 +53,18 @@ export function createMessage<QueueUrl extends string, Shape extends ZodRawShape
5253
MessageBody
5354
}));
5455
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);
6357
}
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+
});
6468

6569
}
6670

@@ -107,4 +111,4 @@ export function QueueHandler<Shape extends ZodRawShape, MetadataShape extends Zo
107111
await cb(parsed);
108112
}
109113
}
110-
}
114+
}

0 commit comments

Comments
 (0)