sqs-consumer 14.2.0-canary.3 → 14.2.1-canary.1

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,5 +1,5 @@
1
- ## [14.2.0-canary.3](https://github.com/bbc/sqs-consumer/compare/v14.2.0-canary.2...v14.2.0-canary.3) (2025-12-12)
1
+ ## [14.2.1-canary.1](https://github.com/bbc/sqs-consumer/compare/v14.2.0...v14.2.1-canary.1) (2025-12-15)
2
2
 
3
3
  ### Chores
4
4
 
5
- * update package version ([62a5d6c](https://github.com/bbc/sqs-consumer/commit/62a5d6c109ad49f736952a681e7de514d426d7df))
5
+ * document graceful shutdowns ([#663](https://github.com/bbc/sqs-consumer/issues/663)) ([c4f77d6](https://github.com/bbc/sqs-consumer/commit/c4f77d6534eea251004ca9c7e652f78d2044f999))
package/README.md CHANGED
@@ -136,6 +136,50 @@ By default, the value of `abort` is set to `false` which means pre existing requ
136
136
 
137
137
  `consumer.stop({ abort: true })`
138
138
 
139
+ #### Graceful shutdowns
140
+
141
+ Calling `consumer.stop()` on its own only prevents new polls from being scheduled. The consumer will emit `stopped` immediately, even if the current long poll or message handler is still running. To wait for the final poll plus any in-flight message processing to finish, set `pollingCompleteWaitTimeMs` to the maximum amount of time you are willing to wait.
142
+
143
+ - While waiting, the consumer emits `waiting_for_polling_to_complete` every second.
144
+ - If the timeout elapses first, `waiting_for_polling_to_complete_timeout_exceeded` fires right before `stopped`.
145
+ - For graceful shutdowns keep `abort: false` (the default). Passing `abort: true` cancels the shared `AbortController`, which halts heartbeat extensions and prevents acknowledgements/deletions from finishing.
146
+
147
+ Here's an example of a graceful shutdown implementation:
148
+
149
+ ```js
150
+ const consumer = Consumer.create({
151
+ queueUrl: "https://sqs.eu-west-1.amazonaws.com/account-id/queue-name",
152
+ handleMessage: async (message) => {
153
+ await doWork(message);
154
+ return message;
155
+ },
156
+ pollingCompleteWaitTimeMs: 10_000, // This will allow up to 10s for the last poll + handler
157
+ });
158
+
159
+ const shutdown = (signal) => {
160
+ console.log(`Received ${signal}, waiting for in-flight work...`);
161
+ consumer.stop();
162
+
163
+ consumer.once("waiting_for_polling_to_complete", () => {
164
+ console.log("Still processing in-flight messages...");
165
+ });
166
+
167
+ consumer.once("waiting_for_polling_to_complete_timeout_exceeded", () => {
168
+ console.warn("Graceful shutdown timed out, continuing shutdown anyway.");
169
+ });
170
+
171
+ consumer.once("stopped", () => {
172
+ console.log("Consumer stopped cleanly");
173
+ process.exit(0);
174
+ });
175
+ };
176
+
177
+ process.once("SIGINT", shutdown);
178
+ process.once("SIGTERM", shutdown);
179
+
180
+ consumer.start();
181
+ ```
182
+
139
183
  ### `consumer.status`
140
184
 
141
185
  Returns the current status of the consumer.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "sqs-consumer",
3
- "version": "14.2.0-canary.3",
3
+ "version": "14.2.1-canary.1",
4
4
  "description": "Build SQS-based Node applications without the boilerplate",
5
5
  "type": "module",
6
6
  "main": "dist/cjs/index.js",