@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/dist/index.mjs CHANGED
@@ -1110,6 +1110,8 @@ var JobManager = class {
1110
1110
  * @internal Not part of public API.
1111
1111
  */
1112
1112
  var JobProcessor = class {
1113
+ /** Guard flag to prevent concurrent poll() execution */
1114
+ _isPolling = false;
1113
1115
  constructor(ctx) {
1114
1116
  this.ctx = ctx;
1115
1117
  }
@@ -1144,7 +1146,18 @@ var JobProcessor = class {
1144
1146
  * the instance-level `instanceConcurrency` limit is reached.
1145
1147
  */
1146
1148
  async poll() {
1147
- if (!this.ctx.isRunning()) return;
1149
+ if (!this.ctx.isRunning() || this._isPolling) return;
1150
+ this._isPolling = true;
1151
+ try {
1152
+ await this._doPoll();
1153
+ } finally {
1154
+ this._isPolling = false;
1155
+ }
1156
+ }
1157
+ /**
1158
+ * Internal poll implementation.
1159
+ */
1160
+ async _doPoll() {
1148
1161
  const { instanceConcurrency } = this.ctx.options;
1149
1162
  if (instanceConcurrency !== void 0 && this.getTotalActiveJobs() >= instanceConcurrency) return;
1150
1163
  for (const [name, worker] of this.ctx.workers) {