this.inFlight = []; // Our work heap of Promises
this.nextTimeout = undefined; // Allow clearTimeout() to reset waiting period.
this.running = false;
+ this.isProcessing = false; // Only let one process() method execute on the work heap at a time
}
/**
async process() {
const _scope = _fileScope('process');
- this.logger.debug(_scope, 'called', {});
+ this.logger.debug(_scope, 'called', { isProcessing: this.isProcessing });
+
+
+ if (this.isProcessing) {
+ return;
+ }
+ this.isProcessing = true;
// Interrupt any pending sleep, if we were called out of timeout-cycle.
clearTimeout(this.nextTimeout);
- // Share one db connection for all tasks.
try {
await this.db.context(async (dbCtx) => {
// No more work, wait a while and retry
this._recurr();
+
+ this.isProcessing = false;
}
}