@fgiova/sqs-consumer 3.4.0 → 3.5.0

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/README.md CHANGED
@@ -86,10 +86,10 @@ const consumer = new SQSConsumer({
86
86
  | messageAttributeNames | string[] | [] | The message attribute names to be included in the response |
87
87
  | attributeNames | string[] | [] | The attribute names to be included in the response |
88
88
  | errorDelaySeconds | number | 0 | Seconds a failed message stays invisible before it can be received again |
89
- | errorDelayBackoff | (attempt: number) => number | | Returns the delay in seconds for a failed message, given its `ApproximateReceiveCount`. Takes precedence over `errorDelaySeconds` |
90
- | maxReceiveCount | number / (attempt: number) => number | | Receive count after which a failed message triggers `onMaxReceiveCountExceeded`. A function receives the `ApproximateReceiveCount` and returns the threshold |
89
+ | errorDelayBackoff | (attempt: number, message: Message) => number | | Returns the delay in seconds for a failed message, given its `ApproximateReceiveCount` and the message itself. Takes precedence over `errorDelaySeconds` |
90
+ | maxReceiveCount | number / (attempt: number, message: Message) => number | | Receive count after which a failed message triggers `onMaxReceiveCountExceeded`. A function receives the `ApproximateReceiveCount` and the message, and returns the threshold |
91
91
 
92
- Delays are truncated to an integer and clamped to the SQS range 0–43200 seconds. When `errorDelayBackoff` is set, `ApproximateReceiveCount` is added to `attributeNames` automatically. If `errorDelayBackoff` throws, the error is reported to `onSQSError` and `errorDelaySeconds` is used instead.
92
+ Delays are truncated to an integer and clamped to the SQS range 0–43200 seconds. When `errorDelayBackoff` is set, `ApproximateReceiveCount` is added to `attributeNames` automatically. If `errorDelayBackoff` throws, the error is reported to `onSQSError` together with the message and `errorDelaySeconds` is used instead.
93
93
 
94
94
  > **Note:** SQS counts the 12-hour visibility limit from when the message was received, not from when the delay is set. A delay that exceeds the remaining time (roughly `43200 - executionTimeout - visibility extensions`) is silently rejected by SQS and the message is retried after its current visibility timeout. Keep delays well below 12 hours, and keep their sum below the queue's `MessageRetentionPeriod`, or the message expires without reaching the DLQ.
95
95
  >
@@ -106,7 +106,7 @@ const consumer = new SQSConsumer({
106
106
  });
107
107
  ```
108
108
 
109
- When a message fails and its `ApproximateReceiveCount` reaches `maxReceiveCount`, the `onMaxReceiveCountExceeded` hook is called with the message and its receive count. **The message is deleted unless a hook returns `false`**, including when no hook is registered: return `false` to release it with the usual error delay instead. When `maxReceiveCount` is set, `ApproximateReceiveCount` is added to `attributeNames` automatically. If the `maxReceiveCount` function throws, the error is reported to `onSQSError` and the message is released.
109
+ When a message fails and its `ApproximateReceiveCount` reaches `maxReceiveCount`, the `onMaxReceiveCountExceeded` hook is called with the message and its receive count. **The message is deleted unless a hook returns `false`**, including when no hook is registered: return `false` to release it with the usual error delay instead. When `maxReceiveCount` is set, `ApproximateReceiveCount` is added to `attributeNames` automatically. If the `maxReceiveCount` function throws, the error is reported to `onSQSError` together with the message and the message is released.
110
110
 
111
111
  > **Note:** if the queue has a redrive policy, set `maxReceiveCount` below the queue's own `maxReceiveCount`, or SQS moves the message to the DLQ before the hook is called.
112
112
 
@@ -24,8 +24,8 @@ type ConsumerOptions = {
24
24
  messageAttributeNames?: string[];
25
25
  attributeNames?: string[];
26
26
  errorDelaySeconds?: number;
27
- errorDelayBackoff?: (attempt: number) => number;
28
- maxReceiveCount?: number | ((attempt: number) => number);
27
+ errorDelayBackoff?: (attempt: number, message: Message) => number;
28
+ maxReceiveCount?: number | ((attempt: number, message: Message) => number);
29
29
  };
30
30
  type ConsumerHookName = Exclude<HookName, "onStart" | "onStop">;
31
31
  export type HooksOptions = {
package/dist/cjs/index.js CHANGED
@@ -160,7 +160,7 @@ class SQSConsumer {
160
160
  result.message.Attributes?.ApproximateReceiveCount ?? 0);
161
161
  if (receiveCount >=
162
162
  (typeof maxReceiveCount === "function"
163
- ? maxReceiveCount(receiveCount)
163
+ ? maxReceiveCount(receiveCount, result.message)
164
164
  : maxReceiveCount)) {
165
165
  const toDelete = await this.hooks.runHook("onMaxReceiveCountExceeded", result.message, receiveCount);
166
166
  if (toDelete) {
@@ -171,17 +171,17 @@ class SQSConsumer {
171
171
  }
172
172
  }
173
173
  catch (e) {
174
- await this.hooks.runHook("onSQSError", e);
174
+ await this.hooks.runHook("onSQSError", e, result.message);
175
175
  }
176
176
  }
177
177
  if (this.consumerOptions.errorDelayBackoff) {
178
178
  try {
179
179
  delaySeconds = this.consumerOptions.errorDelayBackoff(
180
180
  /* c8 ignore next 1 */
181
- Number(result.message.Attributes?.ApproximateReceiveCount ?? 0));
181
+ Number(result.message.Attributes?.ApproximateReceiveCount ?? 0), result.message);
182
182
  }
183
183
  catch (e) {
184
- await this.hooks.runHook("onSQSError", e);
184
+ await this.hooks.runHook("onSQSError", e, result.message);
185
185
  }
186
186
  }
187
187
  candidateToRelease.push({
@@ -24,8 +24,8 @@ type ConsumerOptions = {
24
24
  messageAttributeNames?: string[];
25
25
  attributeNames?: string[];
26
26
  errorDelaySeconds?: number;
27
- errorDelayBackoff?: (attempt: number) => number;
28
- maxReceiveCount?: number | ((attempt: number) => number);
27
+ errorDelayBackoff?: (attempt: number, message: Message) => number;
28
+ maxReceiveCount?: number | ((attempt: number, message: Message) => number);
29
29
  };
30
30
  type ConsumerHookName = Exclude<HookName, "onStart" | "onStop">;
31
31
  export type HooksOptions = {
@@ -153,7 +153,7 @@ export class SQSConsumer {
153
153
  result.message.Attributes?.ApproximateReceiveCount ?? 0);
154
154
  if (receiveCount >=
155
155
  (typeof maxReceiveCount === "function"
156
- ? maxReceiveCount(receiveCount)
156
+ ? maxReceiveCount(receiveCount, result.message)
157
157
  : maxReceiveCount)) {
158
158
  const toDelete = await this.hooks.runHook("onMaxReceiveCountExceeded", result.message, receiveCount);
159
159
  if (toDelete) {
@@ -164,17 +164,17 @@ export class SQSConsumer {
164
164
  }
165
165
  }
166
166
  catch (e) {
167
- await this.hooks.runHook("onSQSError", e);
167
+ await this.hooks.runHook("onSQSError", e, result.message);
168
168
  }
169
169
  }
170
170
  if (this.consumerOptions.errorDelayBackoff) {
171
171
  try {
172
172
  delaySeconds = this.consumerOptions.errorDelayBackoff(
173
173
  /* c8 ignore next 1 */
174
- Number(result.message.Attributes?.ApproximateReceiveCount ?? 0));
174
+ Number(result.message.Attributes?.ApproximateReceiveCount ?? 0), result.message);
175
175
  }
176
176
  catch (e) {
177
- await this.hooks.runHook("onSQSError", e);
177
+ await this.hooks.runHook("onSQSError", e, result.message);
178
178
  }
179
179
  }
180
180
  candidateToRelease.push({
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fgiova/sqs-consumer",
3
- "version": "3.4.0",
3
+ "version": "3.5.0",
4
4
  "main": "./dist/cjs/index.js",
5
5
  "types": "./dist/cjs/index.d.ts",
6
6
  "exports": {