X-Git-Url: http://git.squeep.com/?a=blobdiff_plain;f=src%2Fworker.js;h=ebf891405124e730881b96c1b69d4bf4593be689;hb=HEAD;hp=9b6fd7ab882752f00dc76ae693db8980e8eadc76;hpb=9f9d3c81cc0960f03e6598258d36ad828058f65f;p=websub-hub diff --git a/src/worker.js b/src/worker.js index 9b6fd7a..ebf8914 100644 --- a/src/worker.js +++ b/src/worker.js @@ -42,6 +42,7 @@ class Worker { 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 } /** @@ -177,12 +178,17 @@ class Worker { 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) => { @@ -218,6 +224,8 @@ class Worker { // No more work, wait a while and retry this._recurr(); + + this.isProcessing = false; } }