@bymax-one/nest-queue 1.2.10 → 1.2.11

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.
@@ -1,5 +1,5 @@
1
1
  import * as _nestjs_common from '@nestjs/common';
2
- import { ModuleMetadata, Type, DynamicModule, OnModuleDestroy, HttpException, HttpStatus } from '@nestjs/common';
2
+ import { ModuleMetadata, Type, DynamicModule, OnModuleDestroy, OnApplicationShutdown, HttpException, HttpStatus } from '@nestjs/common';
3
3
  import { JobsOptions, QueueOptions, Telemetry, BulkJobOptions, Queue, Job, FlowJob, JobNode, FlowProducer, Worker, QueueEvents } from 'bullmq';
4
4
  export { FlowJob, FlowProducer, Job, JobNode, JobSchedulerJson, JobsOptions, Queue, QueueEvents, SandboxedJob, Telemetry, Worker } from 'bullmq';
5
5
  import { Redis, RedisOptions } from 'ioredis';
@@ -1013,9 +1013,12 @@ declare class QueueEventsRegistry {
1013
1013
 
1014
1014
  /**
1015
1015
  * @fileoverview `QueueLifecycle` — the single, ordered graceful-shutdown
1016
- * orchestrator. On `onModuleDestroy` it drains every worker within a bounded
1017
- * budget, then tears down queue-events, the connections the library opened,
1018
- * the flow producer, the cached queues, and finally the Queue-role connection.
1016
+ * orchestrator, split across the two NestJS hooks that bracket the HTTP server.
1017
+ * On `onModuleDestroy` it stops consumption: it drains every worker within a
1018
+ * bounded budget, then closes queue-events and the connections the library
1019
+ * opened for them. On `onApplicationShutdown`, which NestJS runs only after the
1020
+ * HTTP server has stopped, it releases what a request can still be using: the
1021
+ * flow producer, the cached queues, and finally the Queue-role connection.
1019
1022
  *
1020
1023
  * Delivery is at-least-once: when a worker exceeds the drain budget it is
1021
1024
  * force-closed and its in-flight job becomes `stalled` and is retried by another
@@ -1028,16 +1031,22 @@ declare class QueueEventsRegistry {
1028
1031
  /**
1029
1032
  * Ordered graceful-shutdown service. Implementing the protocol in one place
1030
1033
  * guarantees the teardown order — workers drain first, then queue-events, then
1031
- * the duplicated connections, then the flow producer, the queues, and finally
1032
- * the Queue-role connection. Every step swallows its own errors so a single
1033
- * failure never aborts the rest of the sequence.
1034
+ * the duplicated connections; once the HTTP server has stopped, the flow
1035
+ * producer, the queues, and finally the Queue-role connection. Every step
1036
+ * swallows its own errors so a single failure never aborts the rest of the
1037
+ * sequence.
1038
+ *
1039
+ * Why two hooks: NestJS runs `onModuleDestroy` before it stops the HTTP server,
1040
+ * so a request that is still being served can enqueue a job after that hook has
1041
+ * returned. The producer side (queues, flow producer, Queue-role connection)
1042
+ * therefore waits for `onApplicationShutdown`, while consumption stops early.
1034
1043
  *
1035
1044
  * Connection ownership: in **Mode B** the library-owned Queue-role client is
1036
1045
  * quit by the connection resolver; in **Mode A** that step is a no-op and only
1037
1046
  * the duplicated worker/queue-events connections the library created are closed
1038
1047
  * — the consumer's shared client is never touched.
1039
1048
  */
1040
- declare class QueueLifecycle implements OnModuleDestroy {
1049
+ declare class QueueLifecycle implements OnModuleDestroy, OnApplicationShutdown {
1041
1050
  private readonly workers;
1042
1051
  private readonly events;
1043
1052
  private readonly queues;
@@ -1045,12 +1054,22 @@ declare class QueueLifecycle implements OnModuleDestroy {
1045
1054
  private readonly connection;
1046
1055
  private readonly resolved;
1047
1056
  private readonly logger;
1057
+ private startedAt;
1058
+ private forcedWorkers;
1048
1059
  constructor(workers: WorkerRegistry, events: QueueEventsRegistry, queues: QueueService, flow: FlowService, connection: ConnectionResolver, resolved: ResolvedQueueOptions);
1049
1060
  /**
1050
- * Run the ordered shutdown sequence. Called by NestJS when the application
1051
- * context closes (e.g. on `SIGTERM` with shutdown hooks enabled).
1061
+ * Stop consumption: drain the workers within the bounded budget, then close
1062
+ * queue-events and the connections the library opened for them. Called by
1063
+ * NestJS when the application context closes (e.g. on `SIGTERM` with shutdown
1064
+ * hooks enabled), before the HTTP server stops.
1052
1065
  */
1053
1066
  onModuleDestroy(): Promise<void>;
1067
+ /**
1068
+ * Release the producer side once the HTTP server has stopped: the optional
1069
+ * queue drain, the flow producer, the cached queues, and the Queue-role
1070
+ * connection, then log the total shutdown time.
1071
+ */
1072
+ onApplicationShutdown(): Promise<void>;
1054
1073
  /**
1055
1074
  * Close every worker with a bounded drain, force-closing any that exceed the
1056
1075
  * budget. Returns the number of workers that had to be force-closed.
@@ -1,5 +1,5 @@
1
1
  import * as _nestjs_common from '@nestjs/common';
2
- import { ModuleMetadata, Type, DynamicModule, OnModuleDestroy, HttpException, HttpStatus } from '@nestjs/common';
2
+ import { ModuleMetadata, Type, DynamicModule, OnModuleDestroy, OnApplicationShutdown, HttpException, HttpStatus } from '@nestjs/common';
3
3
  import { JobsOptions, QueueOptions, Telemetry, BulkJobOptions, Queue, Job, FlowJob, JobNode, FlowProducer, Worker, QueueEvents } from 'bullmq';
4
4
  export { FlowJob, FlowProducer, Job, JobNode, JobSchedulerJson, JobsOptions, Queue, QueueEvents, SandboxedJob, Telemetry, Worker } from 'bullmq';
5
5
  import { Redis, RedisOptions } from 'ioredis';
@@ -1013,9 +1013,12 @@ declare class QueueEventsRegistry {
1013
1013
 
1014
1014
  /**
1015
1015
  * @fileoverview `QueueLifecycle` — the single, ordered graceful-shutdown
1016
- * orchestrator. On `onModuleDestroy` it drains every worker within a bounded
1017
- * budget, then tears down queue-events, the connections the library opened,
1018
- * the flow producer, the cached queues, and finally the Queue-role connection.
1016
+ * orchestrator, split across the two NestJS hooks that bracket the HTTP server.
1017
+ * On `onModuleDestroy` it stops consumption: it drains every worker within a
1018
+ * bounded budget, then closes queue-events and the connections the library
1019
+ * opened for them. On `onApplicationShutdown`, which NestJS runs only after the
1020
+ * HTTP server has stopped, it releases what a request can still be using: the
1021
+ * flow producer, the cached queues, and finally the Queue-role connection.
1019
1022
  *
1020
1023
  * Delivery is at-least-once: when a worker exceeds the drain budget it is
1021
1024
  * force-closed and its in-flight job becomes `stalled` and is retried by another
@@ -1028,16 +1031,22 @@ declare class QueueEventsRegistry {
1028
1031
  /**
1029
1032
  * Ordered graceful-shutdown service. Implementing the protocol in one place
1030
1033
  * guarantees the teardown order — workers drain first, then queue-events, then
1031
- * the duplicated connections, then the flow producer, the queues, and finally
1032
- * the Queue-role connection. Every step swallows its own errors so a single
1033
- * failure never aborts the rest of the sequence.
1034
+ * the duplicated connections; once the HTTP server has stopped, the flow
1035
+ * producer, the queues, and finally the Queue-role connection. Every step
1036
+ * swallows its own errors so a single failure never aborts the rest of the
1037
+ * sequence.
1038
+ *
1039
+ * Why two hooks: NestJS runs `onModuleDestroy` before it stops the HTTP server,
1040
+ * so a request that is still being served can enqueue a job after that hook has
1041
+ * returned. The producer side (queues, flow producer, Queue-role connection)
1042
+ * therefore waits for `onApplicationShutdown`, while consumption stops early.
1034
1043
  *
1035
1044
  * Connection ownership: in **Mode B** the library-owned Queue-role client is
1036
1045
  * quit by the connection resolver; in **Mode A** that step is a no-op and only
1037
1046
  * the duplicated worker/queue-events connections the library created are closed
1038
1047
  * — the consumer's shared client is never touched.
1039
1048
  */
1040
- declare class QueueLifecycle implements OnModuleDestroy {
1049
+ declare class QueueLifecycle implements OnModuleDestroy, OnApplicationShutdown {
1041
1050
  private readonly workers;
1042
1051
  private readonly events;
1043
1052
  private readonly queues;
@@ -1045,12 +1054,22 @@ declare class QueueLifecycle implements OnModuleDestroy {
1045
1054
  private readonly connection;
1046
1055
  private readonly resolved;
1047
1056
  private readonly logger;
1057
+ private startedAt;
1058
+ private forcedWorkers;
1048
1059
  constructor(workers: WorkerRegistry, events: QueueEventsRegistry, queues: QueueService, flow: FlowService, connection: ConnectionResolver, resolved: ResolvedQueueOptions);
1049
1060
  /**
1050
- * Run the ordered shutdown sequence. Called by NestJS when the application
1051
- * context closes (e.g. on `SIGTERM` with shutdown hooks enabled).
1061
+ * Stop consumption: drain the workers within the bounded budget, then close
1062
+ * queue-events and the connections the library opened for them. Called by
1063
+ * NestJS when the application context closes (e.g. on `SIGTERM` with shutdown
1064
+ * hooks enabled), before the HTTP server stops.
1052
1065
  */
1053
1066
  onModuleDestroy(): Promise<void>;
1067
+ /**
1068
+ * Release the producer side once the HTTP server has stopped: the optional
1069
+ * queue drain, the flow producer, the cached queues, and the Queue-role
1070
+ * connection, then log the total shutdown time.
1071
+ */
1072
+ onApplicationShutdown(): Promise<void>;
1054
1073
  /**
1055
1074
  * Close every worker with a bounded drain, force-closing any that exceed the
1056
1075
  * budget. Returns the number of workers that had to be force-closed.