queen-mq 0.12.2 → 0.12.3
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/client-v2/Queen.js +27 -3
- package/client-v2/utils/defaults.js +2 -1
- package/package.json +1 -1
package/client-v2/Queen.js
CHANGED
|
@@ -34,10 +34,12 @@ export class Queen {
|
|
|
34
34
|
// Create buffer manager
|
|
35
35
|
this.#bufferManager = new BufferManager(this.#httpClient)
|
|
36
36
|
|
|
37
|
-
// Setup graceful shutdown
|
|
38
|
-
this.#
|
|
37
|
+
// Setup graceful shutdown (opt-out via handleSignals: false)
|
|
38
|
+
if (this.#config.handleSignals) {
|
|
39
|
+
this.#setupGracefulShutdown()
|
|
40
|
+
}
|
|
39
41
|
|
|
40
|
-
logger.log('Queen.constructor', { status: 'initialized', urls: this.#config.urls.length })
|
|
42
|
+
logger.log('Queen.constructor', { status: 'initialized', urls: this.#config.urls.length, handleSignals: this.#config.handleSignals })
|
|
41
43
|
}
|
|
42
44
|
|
|
43
45
|
#normalizeConfig(config) {
|
|
@@ -454,6 +456,28 @@ export class Queen {
|
|
|
454
456
|
// Graceful Shutdown
|
|
455
457
|
// ===========================
|
|
456
458
|
|
|
459
|
+
/**
|
|
460
|
+
* Register SIGINT/SIGTERM handlers so the client flushes buffers before exit.
|
|
461
|
+
* Called automatically unless handleSignals is set to false.
|
|
462
|
+
*/
|
|
463
|
+
enableGracefulShutdown() {
|
|
464
|
+
if (this.#shutdownHandlers.length > 0) return this
|
|
465
|
+
this.#setupGracefulShutdown()
|
|
466
|
+
return this
|
|
467
|
+
}
|
|
468
|
+
|
|
469
|
+
/**
|
|
470
|
+
* Remove previously registered SIGINT/SIGTERM handlers.
|
|
471
|
+
* Use this when Queen is embedded in a larger application that manages its own lifecycle.
|
|
472
|
+
*/
|
|
473
|
+
disableGracefulShutdown() {
|
|
474
|
+
for (const cleanup of this.#shutdownHandlers) {
|
|
475
|
+
cleanup()
|
|
476
|
+
}
|
|
477
|
+
this.#shutdownHandlers = []
|
|
478
|
+
return this
|
|
479
|
+
}
|
|
480
|
+
|
|
457
481
|
async close() {
|
|
458
482
|
logger.log('Queen.close', 'Starting shutdown')
|
|
459
483
|
console.log('Closing Queen client...')
|
|
@@ -15,7 +15,8 @@ export const CLIENT_DEFAULTS = {
|
|
|
15
15
|
enableFailover: true, // Auto-failover to other servers
|
|
16
16
|
healthRetryAfterMillis: 5000, // Retry unhealthy backends after 5 seconds
|
|
17
17
|
bearerToken: null, // Bearer token for proxy authentication
|
|
18
|
-
headers: {}
|
|
18
|
+
headers: {}, // Custom headers to include in every request
|
|
19
|
+
handleSignals: true // Register SIGINT/SIGTERM handlers (disable when used as a library)
|
|
19
20
|
}
|
|
20
21
|
|
|
21
22
|
export const QUEUE_DEFAULTS = {
|