@adobe/helix-admin-support 3.1.16 → 3.1.18

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 CHANGED
@@ -1,3 +1,17 @@
1
+ ## [3.1.18](https://github.com/adobe/helix-admin-support/compare/v3.1.17...v3.1.18) (2025-01-14)
2
+
3
+
4
+ ### Bug Fixes
5
+
6
+ * 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))
7
+
8
+ ## [3.1.17](https://github.com/adobe/helix-admin-support/compare/v3.1.16...v3.1.17) (2025-01-10)
9
+
10
+
11
+ ### Bug Fixes
12
+
13
+ * reduce batch size ([#353](https://github.com/adobe/helix-admin-support/issues/353)) ([98fa02a](https://github.com/adobe/helix-admin-support/commit/98fa02a625d2b60d5018656bd8d782310c033b5c))
14
+
1
15
  ## [3.1.16](https://github.com/adobe/helix-admin-support/compare/v3.1.15...v3.1.16) (2025-01-07)
2
16
 
3
17
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@adobe/helix-admin-support",
3
- "version": "3.1.16",
3
+ "version": "3.1.18",
4
4
  "description": "Helix Admin Support Library",
5
5
  "main": "src/index.js",
6
6
  "type": "module",
@@ -201,6 +201,22 @@ export class BatchedQueueClient {
201
201
  };
202
202
  }
203
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
+
204
220
  /**
205
221
  * Sends a batch of messages to the `outQueue`.
206
222
  * @param {Message[]} messages
@@ -217,18 +233,18 @@ export class BatchedQueueClient {
217
233
 
218
234
  while (messages.length) {
219
235
  let msg = messages.shift();
220
- let size = JSON.stringify(msg).length;
236
+ let size = Buffer.from(JSON.stringify(msg), 'utf8').length;
221
237
  if (batchSize + size < MAX_BATCH_SIZE) {
222
238
  batch.push(msg);
223
- batchSize += size;
239
+ batchSize += size + 20;
224
240
  } else if (batch.length === 0) {
225
241
  // message doesn't fit in any batch - serializing to s3
226
242
  log.info(`[${msg.MessageGroupId}] message too big: ${hsize(size)}. serializing to s3...`);
227
243
  // eslint-disable-next-line no-await-in-loop
228
244
  msg = await this.serialize(msg);
229
- size = JSON.stringify(msg).length;
245
+ size = Buffer.from(JSON.stringify(msg), 'utf8').length;
230
246
  batch.push(msg);
231
- batchSize += size;
247
+ batchSize += size + 20;
232
248
  } else {
233
249
  // put message back
234
250
  log.info(`[${msg.MessageGroupId}] message too big: ${hsize(size)}. sending current batch...`);
@@ -239,21 +255,28 @@ export class BatchedQueueClient {
239
255
  // if the size limit or the num-messages limit is reached, or of we are done, send the batch
240
256
  if (send || batch.length === 10 || messages.length === 0) {
241
257
  log.info(`sending ${batch.length} messages to ${this.outQueue}...`);
242
- // eslint-disable-next-line no-await-in-loop
243
- const result = await sqs.send(new SendMessageBatchCommand({
258
+ const input = {
244
259
  QueueUrl: this.outQueue,
245
260
  Entries: batch.map((data, idx) => ({
246
261
  Id: `msg${idx}`,
247
262
  ...data,
248
263
  })),
249
- }));
250
- const { Successful = [], Failed = [] } = result;
251
- if (Failed.length) {
252
- log.warn(`failed to send ${Failed.length} to queue.`);
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}`);
253
279
  }
254
- sent += Successful.length;
255
- messageIds.push(...Successful.map(({ MessageId }) => MessageId));
256
- log.info(`sent. ${sent}/${total} (${hsize(batchSize)} to ${this.outQueue} done.`);
257
280
  batch = [];
258
281
  batchSize = 0;
259
282
  send = false;