Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 13 additions & 9 deletions apps/extract-stack/src/create-message.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ export function createMessage<QueueUrl extends string, Shape extends ZodRawShape
}

const sendAll: BatchSend<Shape, MetadataShape> = async (contentArray, metadata) => {
const batches: { Id: string, MessageBody: string }[][] = [];
for (let i = 0; i < contentArray.length; i += 10) {
const contentBatch = contentArray.slice(i, i + 10);
const Entries = contentBatch.map(content => JSON.stringify(messageSchema.parse({ content, metadata })))
Expand All @@ -52,15 +53,18 @@ export function createMessage<QueueUrl extends string, Shape extends ZodRawShape
MessageBody
}));
console.log("sending batch", Entries);
try {
await sqs.sendMessageBatch({
QueueUrl: queueUrl,
Entries
}).promise();
} catch (error) {
console.error(error);
}
batches.push(Entries);
}
const result = await Promise.allSettled(batches.map(batch => sqs.sendMessageBatch({
QueueUrl: queueUrl,
Entries: batch,
}).promise()));

result.forEach((r, i) => {
if (r.status === 'rejected') {
console.error('batch failed', r.reason, batches[i]);
}
});

}

Expand Down Expand Up @@ -107,4 +111,4 @@ export function QueueHandler<Shape extends ZodRawShape, MetadataShape extends Zo
await cb(parsed);
}
}
}
}