@adobe/helix-admin-support 3.1.17 → 3.1.19
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +14 -0
- package/package.json +1 -1
- package/src/BatchedQueueClient.js +37 -17
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,17 @@
|
|
|
1
|
+
## [3.1.19](https://github.com/adobe/helix-admin-support/compare/v3.1.18...v3.1.19) (2025-01-15)
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
### Bug Fixes
|
|
5
|
+
|
|
6
|
+
* **deps:** update dependency @adobe/helix-shared-config to v11.0.14 ([#356](https://github.com/adobe/helix-admin-support/issues/356)) ([a27bc0d](https://github.com/adobe/helix-admin-support/commit/a27bc0d37d51ffdf9231b1ed968113d339a4e68a))
|
|
7
|
+
|
|
8
|
+
## [3.1.18](https://github.com/adobe/helix-admin-support/compare/v3.1.17...v3.1.18) (2025-01-14)
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
### Bug Fixes
|
|
12
|
+
|
|
13
|
+
* improve size calculation and provide fallback ([#355](https://github.com/adobe/helix-admin-support/issues/355)) ([1620b38](https://github.com/adobe/helix-admin-support/commit/1620b38945add78ff21f6c7b4170c01e612e3106))
|
|
14
|
+
|
|
1
15
|
## [3.1.17](https://github.com/adobe/helix-admin-support/compare/v3.1.16...v3.1.17) (2025-01-10)
|
|
2
16
|
|
|
3
17
|
|
package/package.json
CHANGED
|
@@ -20,10 +20,7 @@ import {
|
|
|
20
20
|
PutObjectCommand,
|
|
21
21
|
} from '@aws-sdk/client-s3';
|
|
22
22
|
|
|
23
|
-
|
|
24
|
-
// be on the safe side...need to have a better understanding of how AWS serializes the messages
|
|
25
|
-
// because we see failing messages that are 20k too big.
|
|
26
|
-
const MAX_BATCH_SIZE = 200 * 1024;
|
|
23
|
+
const MAX_BATCH_SIZE = 256 * 1024;
|
|
27
24
|
|
|
28
25
|
const DEFAULT_BUCKET_ID = 'helix-content-bus';
|
|
29
26
|
|
|
@@ -204,6 +201,22 @@ export class BatchedQueueClient {
|
|
|
204
201
|
};
|
|
205
202
|
}
|
|
206
203
|
|
|
204
|
+
/**
|
|
205
|
+
* Stora an undeliverable message in the swap storage.
|
|
206
|
+
* @param {any} msg
|
|
207
|
+
* @returns {String} S3 URL where undeliverable message was stored
|
|
208
|
+
*/
|
|
209
|
+
async storeUndeliverable(input) {
|
|
210
|
+
const swapKey = `${this.swapPrefix}/undeliverable-${Date.now()}.json`;
|
|
211
|
+
await this.s3.send(new PutObjectCommand({
|
|
212
|
+
Body: JSON.stringify(input),
|
|
213
|
+
Bucket: this.swapBucket,
|
|
214
|
+
ContentType: 'application/json',
|
|
215
|
+
Key: swapKey,
|
|
216
|
+
}));
|
|
217
|
+
return `s3://${this.swapBucket}/${swapKey}`;
|
|
218
|
+
}
|
|
219
|
+
|
|
207
220
|
/**
|
|
208
221
|
* Sends a batch of messages to the `outQueue`.
|
|
209
222
|
* @param {Message[]} messages
|
|
@@ -220,18 +233,18 @@ export class BatchedQueueClient {
|
|
|
220
233
|
|
|
221
234
|
while (messages.length) {
|
|
222
235
|
let msg = messages.shift();
|
|
223
|
-
let size = JSON.stringify(msg).length;
|
|
236
|
+
let size = Buffer.from(JSON.stringify(msg), 'utf8').length;
|
|
224
237
|
if (batchSize + size < MAX_BATCH_SIZE) {
|
|
225
238
|
batch.push(msg);
|
|
226
|
-
batchSize += size;
|
|
239
|
+
batchSize += size + 20;
|
|
227
240
|
} else if (batch.length === 0) {
|
|
228
241
|
// message doesn't fit in any batch - serializing to s3
|
|
229
242
|
log.info(`[${msg.MessageGroupId}] message too big: ${hsize(size)}. serializing to s3...`);
|
|
230
243
|
// eslint-disable-next-line no-await-in-loop
|
|
231
244
|
msg = await this.serialize(msg);
|
|
232
|
-
size = JSON.stringify(msg).length;
|
|
245
|
+
size = Buffer.from(JSON.stringify(msg), 'utf8').length;
|
|
233
246
|
batch.push(msg);
|
|
234
|
-
batchSize += size;
|
|
247
|
+
batchSize += size + 20;
|
|
235
248
|
} else {
|
|
236
249
|
// put message back
|
|
237
250
|
log.info(`[${msg.MessageGroupId}] message too big: ${hsize(size)}. sending current batch...`);
|
|
@@ -242,21 +255,28 @@ export class BatchedQueueClient {
|
|
|
242
255
|
// if the size limit or the num-messages limit is reached, or of we are done, send the batch
|
|
243
256
|
if (send || batch.length === 10 || messages.length === 0) {
|
|
244
257
|
log.info(`sending ${batch.length} messages to ${this.outQueue}...`);
|
|
245
|
-
|
|
246
|
-
const result = await sqs.send(new SendMessageBatchCommand({
|
|
258
|
+
const input = {
|
|
247
259
|
QueueUrl: this.outQueue,
|
|
248
260
|
Entries: batch.map((data, idx) => ({
|
|
249
261
|
Id: `msg${idx}`,
|
|
250
262
|
...data,
|
|
251
263
|
})),
|
|
252
|
-
}
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
264
|
+
};
|
|
265
|
+
try {
|
|
266
|
+
// eslint-disable-next-line no-await-in-loop
|
|
267
|
+
const result = await sqs.send(new SendMessageBatchCommand(input));
|
|
268
|
+
const { Successful = [], Failed = [] } = result;
|
|
269
|
+
if (Failed.length) {
|
|
270
|
+
log.warn(`failed to send ${Failed.length} to queue.`);
|
|
271
|
+
}
|
|
272
|
+
sent += Successful.length;
|
|
273
|
+
messageIds.push(...Successful.map(({ MessageId }) => MessageId));
|
|
274
|
+
log.info(`sent. ${sent}/${total} (${hsize(batchSize)} to ${this.outQueue} done.`);
|
|
275
|
+
} catch (e) {
|
|
276
|
+
// eslint-disable-next-line no-await-in-loop
|
|
277
|
+
const s3Url = await this.storeUndeliverable(input);
|
|
278
|
+
log.warn(`Unable to send message batch: ${e.message}, stored in: ${s3Url}`);
|
|
256
279
|
}
|
|
257
|
-
sent += Successful.length;
|
|
258
|
-
messageIds.push(...Successful.map(({ MessageId }) => MessageId));
|
|
259
|
-
log.info(`sent. ${sent}/${total} (${hsize(batchSize)} to ${this.outQueue} done.`);
|
|
260
280
|
batch = [];
|
|
261
281
|
batchSize = 0;
|
|
262
282
|
send = false;
|