@monque/core 1.2.0 → 1.3.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
@@ -26,13 +26,13 @@ A **robust, type-safe MongoDB job queue** for TypeScript with atomic locking, ex
26
26
 
27
27
  ## Features
28
28
 
29
- - 🔒 **Atomic Locking**: Mandatory `findOneAndUpdate` for safe job acquisition in distributed environments.
30
- - 📈 **Exponential Backoff**: Built-in retry logic with configurable backoff strategies.
31
- - 📅 **Cron Scheduling**: Native support for recurring jobs using standard cron syntax.
32
- - 🔍 **Type Safety**: Fully typed job payloads and worker definitions.
33
- - **Event-Driven**: Comprehensive event system for monitoring and logging.
34
- - 🛠️ **Native Driver**: Uses the native MongoDB driver for maximum performance and compatibility.
35
- - 🛑 **Graceful Shutdown**: Ensures all in-progress jobs finish or are safely released before stopping.
29
+ - **Atomic Locking**: Mandatory `findOneAndUpdate` for safe job acquisition in distributed environments.
30
+ - **Exponential Backoff**: Built-in retry logic with configurable backoff strategies.
31
+ - **Cron Scheduling**: Native support for recurring jobs using standard cron syntax.
32
+ - **Type Safety**: Fully typed job payloads and worker definitions.
33
+ - **Event-Driven**: Comprehensive event system for monitoring and logging.
34
+ - **Native Driver**: Uses the native MongoDB driver for maximum performance and compatibility.
35
+ - **Graceful Shutdown**: Ensures all in-progress jobs finish or are safely released before stopping.
36
36
 
37
37
  ## Installation
38
38
 
package/dist/CHANGELOG.md CHANGED
@@ -1,5 +1,15 @@
1
1
  # @monque/core
2
2
 
3
+ ## 1.3.0
4
+
5
+ ### Minor Changes
6
+
7
+ - [#158](https://github.com/ueberBrot/monque/pull/158) [`2f83396`](https://github.com/ueberBrot/monque/commit/2f833966d7798307deaa7a1e655e0623cfb42a3e) Thanks [@renovate](https://github.com/apps/renovate)! - mongodb (^7.0.0 → ^7.1.0)
8
+
9
+ ### Patch Changes
10
+
11
+ - [#160](https://github.com/ueberBrot/monque/pull/160) [`b5fcaf8`](https://github.com/ueberBrot/monque/commit/b5fcaf8be2a49fb1ba97b8d3d9f28f00850f77a1) Thanks [@ueberBrot](https://github.com/ueberBrot)! - Fix race condition where concurrent poll cycles could exceed workerConcurrency limit. Added a guard to prevent overlapping poll() execution from setInterval and change stream triggers.
12
+
3
13
  ## 1.2.0
4
14
 
5
15
  ### Minor Changes
package/dist/README.md CHANGED
@@ -26,13 +26,13 @@ A **robust, type-safe MongoDB job queue** for TypeScript with atomic locking, ex
26
26
 
27
27
  ## Features
28
28
 
29
- - 🔒 **Atomic Locking**: Mandatory `findOneAndUpdate` for safe job acquisition in distributed environments.
30
- - 📈 **Exponential Backoff**: Built-in retry logic with configurable backoff strategies.
31
- - 📅 **Cron Scheduling**: Native support for recurring jobs using standard cron syntax.
32
- - 🔍 **Type Safety**: Fully typed job payloads and worker definitions.
33
- - **Event-Driven**: Comprehensive event system for monitoring and logging.
34
- - 🛠️ **Native Driver**: Uses the native MongoDB driver for maximum performance and compatibility.
35
- - 🛑 **Graceful Shutdown**: Ensures all in-progress jobs finish or are safely released before stopping.
29
+ - **Atomic Locking**: Mandatory `findOneAndUpdate` for safe job acquisition in distributed environments.
30
+ - **Exponential Backoff**: Built-in retry logic with configurable backoff strategies.
31
+ - **Cron Scheduling**: Native support for recurring jobs using standard cron syntax.
32
+ - **Type Safety**: Fully typed job payloads and worker definitions.
33
+ - **Event-Driven**: Comprehensive event system for monitoring and logging.
34
+ - **Native Driver**: Uses the native MongoDB driver for maximum performance and compatibility.
35
+ - **Graceful Shutdown**: Ensures all in-progress jobs finish or are safely released before stopping.
36
36
 
37
37
  ## Installation
38
38
 
package/dist/index.cjs CHANGED
@@ -1,3 +1,4 @@
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
1
2
  let mongodb = require("mongodb");
2
3
  let cron_parser = require("cron-parser");
3
4
  let node_crypto = require("node:crypto");
@@ -1110,6 +1111,8 @@ var JobManager = class {
1110
1111
  * @internal Not part of public API.
1111
1112
  */
1112
1113
  var JobProcessor = class {
1114
+ /** Guard flag to prevent concurrent poll() execution */
1115
+ _isPolling = false;
1113
1116
  constructor(ctx) {
1114
1117
  this.ctx = ctx;
1115
1118
  }
@@ -1144,7 +1147,18 @@ var JobProcessor = class {
1144
1147
  * the instance-level `instanceConcurrency` limit is reached.
1145
1148
  */
1146
1149
  async poll() {
1147
- if (!this.ctx.isRunning()) return;
1150
+ if (!this.ctx.isRunning() || this._isPolling) return;
1151
+ this._isPolling = true;
1152
+ try {
1153
+ await this._doPoll();
1154
+ } finally {
1155
+ this._isPolling = false;
1156
+ }
1157
+ }
1158
+ /**
1159
+ * Internal poll implementation.
1160
+ */
1161
+ async _doPoll() {
1148
1162
  const { instanceConcurrency } = this.ctx.options;
1149
1163
  if (instanceConcurrency !== void 0 && this.getTotalActiveJobs() >= instanceConcurrency) return;
1150
1164
  for (const [name, worker] of this.ctx.workers) {