UNPKG

n8n

Version:

n8n Workflow Automation Tool

54 lines 1.74 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.getInstance = exports.Queue = void 0; const Bull = require("bull"); const config = require("../config"); const ActiveExecutions = require("./ActiveExecutions"); const WebhookHelpers = require("./WebhookHelpers"); class Queue { constructor() { this.activeExecutions = ActiveExecutions.getInstance(); const prefix = config.get('queue.bull.prefix'); const redisOptions = config.get('queue.bull.redis'); this.jobQueue = new Bull('jobs', { prefix, redis: redisOptions, enableReadyCheck: false }); this.jobQueue.on('global:progress', (jobId, progress) => { this.activeExecutions.resolveResponsePromise(progress.executionId, WebhookHelpers.decodeWebhookResponse(progress.response)); }); } async add(jobData, jobOptions) { return this.jobQueue.add(jobData, jobOptions); } async getJob(jobId) { return this.jobQueue.getJob(jobId); } async getJobs(jobTypes) { return this.jobQueue.getJobs(jobTypes); } getBullObjectInstance() { return this.jobQueue; } async stopJob(job) { if (await job.isActive()) { await job.progress(-1); return true; } try { await job.remove(); return true; } catch (e) { await job.progress(-1); } return false; } } exports.Queue = Queue; let activeQueueInstance; function getInstance() { if (activeQueueInstance === undefined) { activeQueueInstance = new Queue(); } return activeQueueInstance; } exports.getInstance = getInstance; //# sourceMappingURL=Queue.js.map