@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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@monque/core",
3
- "version": "1.2.0",
3
+ "version": "1.3.0",
4
4
  "description": "MongoDB-backed job scheduler with atomic locking, exponential backoff, and cron scheduling",
5
5
  "author": "Maurice de Bruyn <debruyn.maurice@gmail.com>",
6
6
  "repository": {
@@ -72,17 +72,17 @@
72
72
  "cron-parser": "^5.5.0"
73
73
  },
74
74
  "peerDependencies": {
75
- "mongodb": "catalog:"
75
+ "mongodb": "^7.1.0"
76
76
  },
77
77
  "devDependencies": {
78
- "@faker-js/faker": "^10.2.0",
79
- "@testcontainers/mongodb": "catalog:",
80
- "@total-typescript/ts-reset": "catalog:",
81
- "@types/node": "catalog:",
82
- "@vitest/coverage-v8": "catalog:",
78
+ "@faker-js/faker": "^10.3.0",
79
+ "@testcontainers/mongodb": "^11.12.0",
80
+ "@total-typescript/ts-reset": "^0.6.1",
81
+ "@types/node": "^22.19.11",
82
+ "@vitest/coverage-v8": "^4.0.18",
83
83
  "fishery": "^2.4.0",
84
- "mongodb": "catalog:",
85
- "tsdown": "catalog:",
86
- "vitest": "catalog:"
84
+ "mongodb": "^7.1.0",
85
+ "tsdown": "^0.20.3",
86
+ "vitest": "^4.0.18"
87
87
  }
88
88
  }
@@ -13,6 +13,9 @@ import type { SchedulerContext } from './types.js';
13
13
  * @internal Not part of public API.
14
14
  */
15
15
  export class JobProcessor {
16
+ /** Guard flag to prevent concurrent poll() execution */
17
+ private _isPolling = false;
18
+
16
19
  constructor(private readonly ctx: SchedulerContext) {}
17
20
 
18
21
  /**
@@ -56,10 +59,23 @@ export class JobProcessor {
56
59
  * the instance-level `instanceConcurrency` limit is reached.
57
60
  */
58
61
  async poll(): Promise<void> {
59
- if (!this.ctx.isRunning()) {
62
+ if (!this.ctx.isRunning() || this._isPolling) {
60
63
  return;
61
64
  }
62
65
 
66
+ this._isPolling = true;
67
+
68
+ try {
69
+ await this._doPoll();
70
+ } finally {
71
+ this._isPolling = false;
72
+ }
73
+ }
74
+
75
+ /**
76
+ * Internal poll implementation.
77
+ */
78
+ private async _doPoll(): Promise<void> {
63
79
  // Early exit if global instanceConcurrency is reached
64
80
  const { instanceConcurrency } = this.ctx.options;
65
81