diff --git a/lib/commonjs/Queue.js b/lib/commonjs/Queue.js index ba18967..59ef6f9 100644 --- a/lib/commonjs/Queue.js +++ b/lib/commonjs/Queue.js @@ -1,47 +1,26 @@ -'use strict'; +"use strict"; -Object.defineProperty(exports, '__esModule', { - value: true, +Object.defineProperty(exports, "__esModule", { + value: true }); exports.default = exports.QueueError = exports.Queue = void 0; -var _reactNative = require('react-native'); -var _Job = require('./models/Job'); -var _Uuid = require('./utils/Uuid'); -var _Worker = require('./Worker'); -var _eventemitter = _interopRequireDefault(require('eventemitter3')); +var _reactNative = require("react-native"); +var _Job = require("./models/Job"); +var _Uuid = require("./utils/Uuid"); +var _Worker = require("./Worker"); +var _eventemitter = _interopRequireDefault(require("eventemitter3")); var _Queue; -function _interopRequireDefault(e) { - return e && e.__esModule ? e : { default: e }; -} -function _defineProperty(e, r, t) { - return ( - (r = _toPropertyKey(r)) in e - ? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 }) - : (e[r] = t), - e - ); -} -function _toPropertyKey(t) { - var i = _toPrimitive(t, 'string'); - return 'symbol' == typeof i ? i : i + ''; -} -function _toPrimitive(t, r) { - if ('object' != typeof t || !t) return t; - var e = t[Symbol.toPrimitive]; - if (void 0 !== e) { - var i = e.call(t, r || 'default'); - if ('object' != typeof i) return i; - throw new TypeError('@@toPrimitive must return a primitive value.'); - } - return ('string' === r ? String : Number)(t); -} /* eslint-disable no-extra-boolean-cast */ /* eslint-disable @typescript-eslint/no-empty-function */ +function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; } +function _defineProperty(e, r, t) { return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : e[r] = t, e; } +function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == typeof i ? i : i + ""; } +function _toPrimitive(t, r) { if ("object" != typeof t || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != typeof i) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); } /* eslint-disable no-extra-boolean-cast */ /* eslint-disable @typescript-eslint/no-empty-function */ class QueueError extends Error { - constructor(message, code = 'error') { - super(message); - _defineProperty(this, 'code', void 0); - this.name = 'QueueError'; - this.code = code; - } + constructor(message, code = "error") { + super(message); + _defineProperty(this, "code", void 0); + this.name = 'QueueError'; + this.code = code; + } } /** @@ -72,415 +51,427 @@ exports.QueueError = QueueError; * ``` */ class Queue extends _eventemitter.default { - static get instance() { - if (this.queueInstance) { - return this.queueInstance; - } else { - this.queueInstance = new Queue(); - return this.queueInstance; - } + static get instance() { + if (this.queueInstance) { + return this.queueInstance; + } else { + this.queueInstance = new Queue(); + return this.queueInstance; } - /** - * @returns true if the Queue is running and false otherwise - */ - get isRunning() { - return this.isActive; - } - /** - * @returns the workers map (readonly) - */ - get registeredWorkers() { - return this.workers; - } - constructor() { - super(); - _defineProperty(this, 'emitter', new _eventemitter.default()); - _defineProperty(this, 'jobStore', void 0); - _defineProperty(this, 'workers', void 0); - _defineProperty(this, 'isActive', void 0); - _defineProperty(this, 'timeoutId', void 0); - _defineProperty(this, 'executedJobs', void 0); - _defineProperty(this, 'activeJobCount', void 0); - _defineProperty(this, 'concurrency', void 0); - _defineProperty(this, 'updateInterval', void 0); - _defineProperty(this, 'onQueueFinish', void 0); - _defineProperty(this, 'queuedJobExecuter', []); - _defineProperty(this, 'runningJobPromises', void 0); - _defineProperty(this, 'resetActiveJob', (job) => { - this.jobStore.updateJob({ - ...job, - ...{ - active: _Job.FALSE, - }, - }); - }); - _defineProperty(this, 'runQueue', async () => { - if (!this.isActive) { - this.finishQueue(); - return; - } - const nextJob = await this.jobStore.getNextJob(); - if (this.isJobNotEmpty(nextJob)) { - const nextJobs = await this.getJobsForWorker(nextJob.workerName); - const processingJobs = nextJobs.map(async (job) => this.limitExecution(this.excuteJob, job)); - await Promise.all(processingJobs); - } else if (!this.isExecuting()) { - this.finishQueue(); - return; - } - this.scheduleQueue(); - }); - _defineProperty(this, 'limitExecution', async (executer, rawJob) => { - return new Promise(async (resolve) => await this.enqueueJobExecuter(executer, resolve, rawJob)); + } + /** + * @returns true if the Queue is running and false otherwise + */ + get isRunning() { + return this.isActive; + } + /** + * @returns the workers map (readonly) + */ + get registeredWorkers() { + return this.workers; + } + constructor() { + super(); + _defineProperty(this, "emitter", new _eventemitter.default()); + _defineProperty(this, "jobStore", void 0); + _defineProperty(this, "workers", void 0); + _defineProperty(this, "isActive", void 0); + _defineProperty(this, "timeoutId", void 0); + _defineProperty(this, "executedJobs", void 0); + _defineProperty(this, "activeJobCount", void 0); + _defineProperty(this, "concurrency", void 0); + _defineProperty(this, "updateInterval", void 0); + _defineProperty(this, "onQueueFinish", void 0); + _defineProperty(this, "queuedJobExecuter", []); + _defineProperty(this, "runningJobPromises", void 0); + _defineProperty(this, "resetActiveJob", job => { + this.jobStore.updateJob({ + ...job, + ...{ + active: _Job.FALSE + } + }); + }); + _defineProperty(this, "runQueue", async () => { + if (!this.isActive) { + this.finishQueue(); + return; + } + const nextJob = await this.jobStore.getNextJob(); + if (this.isJobNotEmpty(nextJob)) { + const nextJobs = await this.getJobsForWorker(nextJob.workerName); + const processingJobs = nextJobs.map(async job => this.limitExecution(this.excuteJob, job)); + await Promise.all(processingJobs); + } else if (!this.isExecuting()) { + this.finishQueue(); + return; + } + this.scheduleQueue(); + }); + _defineProperty(this, "limitExecution", async (executer, rawJob) => { + return new Promise(async resolve => await this.enqueueJobExecuter(executer, resolve, rawJob)); + }); + _defineProperty(this, "enqueueJobExecuter", async (executer, resolve, rawJob) => { + if (this.isExecuterAvailable()) { + await this.runExecuter(executer, resolve, rawJob); + } else { + this.queuedJobExecuter.push(this.runExecuter.bind(null, executer, resolve, rawJob)); + } + }); + _defineProperty(this, "runExecuter", async (executer, resolve, rawJob) => { + try { + await executer(rawJob); + } finally { + resolve(true); + if (this.queuedJobExecuter.length > 0 && this.isExecuterAvailable()) { + await this.queuedJobExecuter.shift()(); + } + } + }); + _defineProperty(this, "excuteJob", async rawJob => { + const worker = this.workers[rawJob.workerName]; + const payload = JSON.parse(rawJob.payload); + const job = { + ...rawJob, + ...{ + payload + } + }; + try { + job.status = "processing"; + this.jobStore.updateJob({ + ...job, + payload: JSON.stringify(payload) }); - _defineProperty(this, 'enqueueJobExecuter', async (executer, resolve, rawJob) => { - if (this.isExecuterAvailable()) { - await this.runExecuter(executer, resolve, rawJob); - } else { - this.queuedJobExecuter.push(this.runExecuter.bind(null, executer, resolve, rawJob)); - } + this.emit('jobStarted', job); + this.activeJobCount++; + if (!this.workers[rawJob.workerName]) { + throw new QueueError(`Missing worker with name ${rawJob.workerName}`, "error"); + } + const promise = worker.execute(rawJob); + this.runningJobPromises[rawJob.id] = promise; + await promise; + worker.triggerSuccess(job); + job.status = "finished"; + this.jobStore.updateJob({ + ...job, + payload: JSON.stringify(payload) }); - _defineProperty(this, 'runExecuter', async (executer, resolve, rawJob) => { - try { - await executer(rawJob); - } finally { - resolve(true); - if (this.queuedJobExecuter.length > 0 && this.isExecuterAvailable()) { - await this.queuedJobExecuter.shift()(); - } - } + this.jobStore.removeJob(rawJob); + this.emit('jobSucceeded', job); + } catch (err) { + const error = err; + const { + attempts + } = rawJob; + // eslint-disable-next-line prefer-const + let { + errors, + failedAttempts + } = JSON.parse(rawJob.metaData); + failedAttempts++; + let failed = ''; + if (failedAttempts >= attempts) { + failed = new Date().toISOString(); + } + const metaData = JSON.stringify({ + errors: [...errors, error], + failedAttempts }); - _defineProperty(this, 'excuteJob', async (rawJob) => { - const worker = this.workers[rawJob.workerName]; - const payload = JSON.parse(rawJob.payload); - const job = { - ...rawJob, - ...{ - payload, - }, - }; - try { - job.status = 'processing'; - this.jobStore.updateJob({ - ...job, - payload: JSON.stringify(payload), - }); - this.emit('jobStarted', job); - this.activeJobCount++; - if (!this.workers[rawJob.workerName]) { - throw new QueueError(`Missing worker with name ${rawJob.workerName}`, 'error'); - } - const promise = worker.execute(rawJob); - this.runningJobPromises[rawJob.id] = promise; - await promise; - worker.triggerSuccess(job); - job.status = 'finished'; - this.jobStore.updateJob({ - ...job, - payload: JSON.stringify(payload), - }); - this.jobStore.removeJob(rawJob); - this.emit('jobSucceeded', job); - } catch (err) { - const error = err; - const { attempts } = rawJob; - // eslint-disable-next-line prefer-const - let { errors, failedAttempts } = JSON.parse(rawJob.metaData); - failedAttempts++; - let failed = ''; - if (failedAttempts >= attempts) { - failed = new Date().toISOString(); - } - const metaData = JSON.stringify({ - errors: [...errors, error], - failedAttempts, - }); - worker.triggerFailure( - { - ...job, - metaData, - failed, - }, - error - ); - const failedJob = { - ...rawJob, - ...{ - active: _Job.FALSE, - metaData, - failed, - status: error.code === 'cancelled' ? 'cancelled' : 'failed', - }, - }; - this.jobStore.updateJob(failedJob); - this.emit('jobFailed', failedJob, error); - } finally { - delete this.runningJobPromises[job.id]; - worker.decreaseExecutionCount(); - worker.triggerCompletion(job); - this.emit('jobCompleted', { - ...job, - }); - this.executedJobs.push(rawJob); - this.activeJobCount--; - } + worker.triggerFailure({ + ...job, + metaData, + failed + }, error); + const failedJob = { + ...rawJob, + ...{ + active: _Job.FALSE, + metaData, + failed, + status: error.code === "cancelled" ? "cancelled" : "failed" + } + }; + this.jobStore.updateJob(failedJob); + this.emit('jobFailed', failedJob, error); + } finally { + delete this.runningJobPromises[job.id]; + worker.decreaseExecutionCount(); + worker.triggerCompletion(job); + this.emit('jobCompleted', { + ...job }); - this.jobStore = _reactNative.NativeModules.JobQueue; - this.workers = {}; - this.runningJobPromises = {}; - this.isActive = false; - this.timeoutId = 0; - this.executedJobs = []; - this.activeJobCount = 0; - this.updateInterval = 10; - this.onQueueFinish = (executedJobs) => {}; - this.concurrency = -1; - } + this.executedJobs.push(rawJob); + this.activeJobCount--; + } + }); + this.jobStore = _reactNative.NativeModules.JobQueue; + this.workers = {}; + this.runningJobPromises = {}; + this.isActive = false; + this.timeoutId = 0; + this.executedJobs = []; + this.activeJobCount = 0; + this.updateInterval = 10; + this.onQueueFinish = executedJobs => {}; + this.concurrency = -1; + } - /** - * @returns a promise that resolves all jobs of jobStore - */ - async getJobs() { - return await this.jobStore.getJobs(); - } - async getJobsWithDeleted() { - return await this.jobStore.getJobsWithDeleted(); - } - /** - * @param job the job to be deleted - */ - removeJob(job) { - this.jobStore.removeJob(job); - this.emit('jobDeleted', job); - } - removeJobPermanent(job) { - this.jobStore.removeJobPermanently(job); - this.emit('jobDeleted', job); - } - /** - * @param job the job which should be requeued - */ - requeueJob(job) { - this.jobStore.updateJob({ - ...job, - failed: '', - status: 'idle', - active: _Job.TRUE, - }); - if (!this.isActive) { - // eslint-disable-next-line @typescript-eslint/ban-ts-comment - // @ts-ignore - this.start() - .then(() => { - console.log('Queue restarted'); - }) - .catch(() => { - console.log('Queue could not be restarted'); - }); - } + /** + * @returns a promise that resolves all jobs of jobStore + */ + async getJobs() { + return await this.jobStore.getJobs(); + } + async getJobsWithDeleted() { + return await this.jobStore.getJobsWithDeleted(); + } + /** + * @param job the job to be deleted + */ + removeJob(job) { + this.jobStore.removeJob(job); + this.emit("jobDeleted", job); + } + removeJobPermanent(job) { + this.jobStore.removeJobPermanently(job); + this.emit("jobDeleted", job); + } + /** + * @param job the job which should be requeued + */ + requeueJob(job) { + this.jobStore.updateJob({ + ...job, + failed: '', + status: "idle", + active: _Job.TRUE + }); + if (!this.isActive) { + // eslint-disable-next-line @typescript-eslint/ban-ts-comment + // @ts-ignore + this.start().then(() => { + console.log("Queue restarted"); + }).catch(() => { + console.log("Queue could not be restarted"); + }); } - configure(options) { - const { onQueueFinish = (executedJobs) => {}, updateInterval = 10, concurrency = -1 } = options; - this.onQueueFinish = onQueueFinish; - this.updateInterval = updateInterval; - this.concurrency = concurrency; - } - /** - * adds a [[Worker]] to the queue which can execute Jobs - * @param worker - */ - addWorker(worker) { - if (this.workers[worker.name]) { - throw new QueueError(`Worker "${worker.name}" already exists.`, 'error'); - } - this.workers[worker.name] = worker; - this.emit('workerAdded', worker.name); + } + configure(options) { + const { + onQueueFinish = executedJobs => {}, + updateInterval = 10, + concurrency = -1 + } = options; + this.onQueueFinish = onQueueFinish; + this.updateInterval = updateInterval; + this.concurrency = concurrency; + } + /** + * adds a [[Worker]] to the queue which can execute Jobs + * @param worker + */ + addWorker(worker) { + if (this.workers[worker.name]) { + throw new QueueError(`Worker "${worker.name}" already exists.`, "error"); } + this.workers[worker.name] = worker; + this.emit('workerAdded', worker.name); + } - /** - * removes worker from queue - * - * @param name - * @param [deleteRelatedJobs=false] removes all queued jobs releated to the worker if set to true - */ - removeWorker(name, deleteRelatedJobs = false) { - delete this.workers[name]; - if (deleteRelatedJobs) { - this.jobStore.removeJobsByWorkerName(name); - } + /** + * removes worker from queue + * + * @param name + * @param [deleteRelatedJobs=false] removes all queued jobs releated to the worker if set to true + */ + removeWorker(name, deleteRelatedJobs = false) { + delete this.workers[name]; + if (deleteRelatedJobs) { + this.jobStore.removeJobsByWorkerName(name); } + } - /** - * adds a job to the queue - * @param workerName name of the worker which should be used to excute the job - * @param [payload={}] payload which is passed as parameter to the executer - * @param [options={ attempts: 0, timeout: 0, priority: 0 }] options to set max attempts, a timeout and a priority - * @param [startQueue=true] if set to false the queue won't start automaticly when adding a job - * @returns job id - */ - addJob( - workerName, - payload, - options = { - attempts: 0, - timeout: 0, - priority: 0, - }, - startQueue = true - ) { - const { attempts = 0, timeout = 0, priority = 0 } = options; - const id = _Uuid.Uuid.v4(); - const job = { - id, - payload: JSON.stringify(payload || {}), - metaData: JSON.stringify({ - failedAttempts: 0, - errors: [], - }), - active: _Job.FALSE, - created: new Date().toISOString(), - failed: '', - workerName, - attempts, - timeout, - priority, - isDeleted: false, - status: 'idle', - }; - if (!this.workers[job.workerName]) { - throw new QueueError(`Missing worker with name ${job.workerName}`); - } - this.jobStore.addJob(job); - this.emit('jobAdded', job); - if (startQueue && !this.isActive) { - this.start(); - } - return id; + /** + * adds a job to the queue + * @param workerName name of the worker which should be used to excute the job + * @param [payload={}] payload which is passed as parameter to the executer + * @param [options={ attempts: 0, timeout: 0, priority: 0 }] options to set max attempts, a timeout and a priority + * @param [startQueue=true] if set to false the queue won't start automaticly when adding a job + * @returns job id + */ + addJob(workerName, payload, options = { + attempts: 0, + timeout: 0, + priority: 0 + }, startQueue = true) { + const { + attempts = 0, + timeout = 0, + priority = 0 + } = options; + const id = _Uuid.Uuid.v4(); + const job = { + id, + payload: JSON.stringify(payload || {}), + metaData: JSON.stringify({ + failedAttempts: 0, + errors: [] + }), + active: _Job.FALSE, + created: new Date().toISOString(), + failed: '', + workerName, + attempts, + timeout, + priority, + isDeleted: false, + status: "idle" + }; + if (!this.workers[job.workerName]) { + throw new QueueError(`Missing worker with name ${job.workerName}`); } - /** - * starts the queue to execute queued jobs - */ - async start() { - if (!this.isActive) { - this.isActive = true; - this.executedJobs = []; - await this.resetActiveJobs(); - this.scheduleQueue(); - } + this.jobStore.addJob(job); + this.emit('jobAdded', job); + if (startQueue && !this.isActive) { + this.start(); } - /** - * stop the queue from executing queued jobs - */ - stop() { - this.isActive = false; + return id; + } + /** + * starts the queue to execute queued jobs + */ + async start() { + if (!this.isActive) { + this.isActive = true; + this.executedJobs = []; + await this.resetActiveJobs(); + this.scheduleQueue(); } + } + /** + * stop the queue from executing queued jobs + */ + stop() { + this.isActive = false; + } - /** - * cancel running job - */ - cancelJob(jobId, exception) { - const promise = this.runningJobPromises[jobId]; - if (promise !== undefined && typeof promise[_Worker.CANCEL] === 'function') { - promise[_Worker.CANCEL](exception || new QueueError(`job canceled`, 'cancelled')); - } else if (!promise[_Worker.CANCEL]) { - console.warn('Worker does not have a cancel method implemented'); - } else { - throw new QueueError(`Job with id ${jobId} not currently running`, 'error'); - } + /** + * cancel running job + */ + cancelJob(jobId, exception) { + const promise = this.runningJobPromises[jobId]; + if (promise !== undefined && typeof promise[_Worker.CANCEL] === 'function') { + promise[_Worker.CANCEL](exception || new QueueError(`job canceled`, "cancelled")); + } else if (!promise[_Worker.CANCEL]) { + console.warn('Worker does not have a cancel method implemented'); + } else { + throw new QueueError(`Job with id ${jobId} not currently running`, "error"); } - async cancelAllActiveJobs() { - const jobs = await this.jobStore.getActiveMarkedJobs(); - jobs.forEach((job) => { - const newJob = { - ...job, - ...{ - active: _Job.FALSE, - status: 'cancelled', - }, - }; - const isRunning = this.runningJobPromises[job.id]; - // eslint-disable-next-line @typescript-eslint/no-misused-promises - if (!!Boolean(isRunning)) { - this.cancelJob(job.id, new QueueError(`Job with id ${job.id} cancelled`, 'cancelled')); - } - this.jobStore.updateJob(newJob); - this.emit('jobCancelled', newJob); - }); - } - cancelActiveJob(job) { - const newJob = { - ...job, - ...{ - active: _Job.FALSE, - status: 'cancelled', - }, - }; - const isRunning = this.runningJobPromises[job.id]; - // eslint-disable-next-line @typescript-eslint/no-misused-promises - if (!!isRunning) { - this.cancelJob(job.id, new QueueError(`Job with id ${job.id} cancelled`, 'cancelled')); - } - this.jobStore.updateJob(newJob); - this.emit('jobCancelled', newJob); - } - async resetActiveJobs() { - const activeMarkedJobs = await this.jobStore.getActiveMarkedJobs(); - const resetTasks = activeMarkedJobs.map(this.resetActiveJob); - await Promise.all(resetTasks); - } - scheduleQueue() { - if (_reactNative.AppState.currentState === 'active' && _reactNative.Platform.OS === 'ios') { - this.timeoutId = setTimeout(this.runQueue, this.updateInterval); - } else { - this.runQueue(); + } + async cancelAllActiveJobs() { + const jobs = await this.jobStore.getActiveMarkedJobs(); + jobs.forEach(job => { + const newJob = { + ...job, + ...{ + active: _Job.FALSE, + status: "cancelled" } + }; + const isRunning = this.runningJobPromises[job.id]; + // eslint-disable-next-line @typescript-eslint/no-misused-promises + if (!!Boolean(isRunning)) { + this.cancelJob(job.id, new QueueError(`Job with id ${job.id} cancelled`, "cancelled")); + } + this.jobStore.updateJob(newJob); + this.emit('jobCancelled', newJob); + }); + } + cancelActiveJob(job) { + const newJob = { + ...job, + ...{ + active: _Job.FALSE, + status: "cancelled" + } + }; + const isRunning = this.runningJobPromises[job.id]; + // eslint-disable-next-line @typescript-eslint/no-misused-promises + if (!!isRunning) { + this.cancelJob(job.id, new QueueError(`Job with id ${job.id} cancelled`, "cancelled")); } - isJobNotEmpty(rawJob) { - return Object.keys(rawJob).length > 0; + this.jobStore.updateJob(newJob); + this.emit('jobCancelled', newJob); + } + async resetActiveJobs() { + const activeMarkedJobs = await this.jobStore.getActiveMarkedJobs(); + const resetTasks = activeMarkedJobs.map(this.resetActiveJob); + await Promise.all(resetTasks); + } + scheduleQueue() { + if (_reactNative.AppState.currentState === 'active' && _reactNative.Platform.OS === "ios") { + this.timeoutId = setTimeout(this.runQueue, this.updateInterval); + } else { + this.runQueue(); } - isExecuterAvailable() { - return this.concurrency <= 0 || this.activeJobCount < this.concurrency; + } + isJobNotEmpty(rawJob) { + return Object.keys(rawJob).length > 0; + } + isExecuterAvailable() { + return this.concurrency <= 0 || this.activeJobCount < this.concurrency; + } + isExecuting() { + return this.activeJobCount > 0; + } + finishQueue() { + this.onQueueFinish(this.executedJobs); + this.isActive = false; + clearTimeout(this.timeoutId); + } + async getJobsForWorker(workerName) { + const { + isBusy, + availableExecuters + } = this.workers[workerName]; + if (!isBusy) { + return await this.jobStore.getJobsForWorker(workerName, availableExecuters); + } else { + return await this.getJobsForAlternateWorker(); } - isExecuting() { - return this.activeJobCount > 0; + } + async getJobsForWorkerWithDeleted(workerName) { + const { + isBusy, + availableExecuters + } = this.workers[workerName]; + if (!isBusy) { + return await this.jobStore.getJobsForWorkerWithDeleted(workerName, availableExecuters); + } else { + return await this.getJobsForAlternateWorker(); } - finishQueue() { - this.onQueueFinish(this.executedJobs); - this.isActive = false; - clearTimeout(this.timeoutId); - } - async getJobsForWorker(workerName) { - const { isBusy, availableExecuters } = this.workers[workerName]; - if (!isBusy) { - return await this.jobStore.getJobsForWorker(workerName, availableExecuters); - } else { - return await this.getJobsForAlternateWorker(); - } - } - async getJobsForWorkerWithDeleted(workerName) { - const { isBusy, availableExecuters } = this.workers[workerName]; - if (!isBusy) { - return await this.jobStore.getJobsForWorkerWithDeleted(workerName, availableExecuters); - } else { - return await this.getJobsForAlternateWorker(); - } - } - async getJobsForAlternateWorker() { - for (const workerName of Object.keys(this.workers)) { - const { isBusy, availableExecuters } = this.workers[workerName]; - let nextJobs = []; - if (!isBusy) { - nextJobs = await this.jobStore.getJobsForWorker(workerName, availableExecuters); - } - if (nextJobs.length > 0) { - return nextJobs; - } - } - return []; + } + async getJobsForAlternateWorker() { + for (const workerName of Object.keys(this.workers)) { + const { + isBusy, + availableExecuters + } = this.workers[workerName]; + let nextJobs = []; + if (!isBusy) { + nextJobs = await this.jobStore.getJobsForWorker(workerName, availableExecuters); + } + if (nextJobs.length > 0) { + return nextJobs; + } } + return []; + } } exports.Queue = Queue; _Queue = Queue; -_defineProperty(Queue, 'queueInstance', void 0); -var _default = (exports.default = Queue.instance); -//# sourceMappingURL=Queue.js.map +_defineProperty(Queue, "queueInstance", void 0); +var _default = exports.default = Queue.instance; +//# sourceMappingURL=Queue.js.map \ No newline at end of file diff --git a/lib/commonjs/Queue.js.map b/lib/commonjs/Queue.js.map index d3df5b2..52a0f21 100644 --- a/lib/commonjs/Queue.js.map +++ b/lib/commonjs/Queue.js.map @@ -1,178 +1 @@ -{ - "version": 3, - "names": [ - "_reactNative", - "require", - "_Job", - "_Uuid", - "_Worker", - "_eventemitter", - "_interopRequireDefault", - "_Queue", - "e", - "__esModule", - "default", - "_defineProperty", - "r", - "t", - "_toPropertyKey", - "Object", - "defineProperty", - "value", - "enumerable", - "configurable", - "writable", - "i", - "_toPrimitive", - "Symbol", - "toPrimitive", - "call", - "TypeError", - "String", - "Number", - "QueueError", - "Error", - "constructor", - "message", - "code", - "name", - "exports", - "Queue", - "EventEmitter", - "instance", - "queueInstance", - "isRunning", - "isActive", - "registeredWorkers", - "workers", - "job", - "jobStore", - "updateJob", - "active", - "FALSE", - "finishQueue", - "nextJob", - "getNextJob", - "isJobNotEmpty", - "nextJobs", - "getJobsForWorker", - "workerName", - "processingJobs", - "map", - "limitExecution", - "excuteJob", - "Promise", - "all", - "isExecuting", - "scheduleQueue", - "executer", - "rawJob", - "resolve", - "enqueueJobExecuter", - "isExecuterAvailable", - "runExecuter", - "queuedJobExecuter", - "push", - "bind", - "length", - "shift", - "worker", - "payload", - "JSON", - "parse", - "status", - "stringify", - "emit", - "activeJobCount", - "promise", - "execute", - "runningJobPromises", - "id", - "triggerSuccess", - "removeJob", - "err", - "error", - "attempts", - "errors", - "failedAttempts", - "metaData", - "failed", - "Date", - "toISOString", - "triggerFailure", - "failedJob", - "decreaseExecutionCount", - "triggerCompletion", - "executedJobs", - "NativeModules", - "JobQueue", - "timeoutId", - "updateInterval", - "onQueueFinish", - "concurrency", - "getJobs", - "getJobsWithDeleted", - "removeJobPermanent", - "removeJobPermanently", - "requeueJob", - "TRUE", - "start", - "then", - "console", - "log", - "catch", - "configure", - "options", - "addWorker", - "removeWorker", - "deleteRelatedJobs", - "removeJobsByWorkerName", - "addJob", - "timeout", - "priority", - "startQueue", - "Uuid", - "v4", - "created", - "isDeleted", - "resetActiveJobs", - "stop", - "cancelJob", - "jobId", - "exception", - "undefined", - "CANCEL", - "warn", - "cancelAllActiveJobs", - "jobs", - "getActiveMarkedJobs", - "forEach", - "newJob", - "Boolean", - "cancelActiveJob", - "activeMarkedJobs", - "resetTasks", - "resetActiveJob", - "AppState", - "currentState", - "Platform", - "OS", - "setTimeout", - "runQueue", - "keys", - "clearTimeout", - "isBusy", - "availableExecuters", - "getJobsForAlternateWorker", - "getJobsForWorkerWithDeleted", - "_default" - ], - "sources": [ - "Queue.ts" - ], - "sourcesContent": [ - "/* eslint-disable no-extra-boolean-cast */\n/* eslint-disable @typescript-eslint/no-empty-function */\nimport { AppState, NativeModules, Platform } from 'react-native';\n\nimport { FALSE, Job, RawJob, TRUE } from './models/Job';\nimport { JobStore } from './models/JobStore';\nimport { Uuid } from './utils/Uuid';\nimport { Worker, CANCEL, CancellablePromise } from './Worker';\n\n\nimport EventEmitter from 'eventemitter3';\n\ntype QueueErrorType = \"cancelled\" | \"error\";\n\nexport class QueueError extends Error {\n code: QueueErrorType;\n constructor(message: string, code: QueueErrorType = \"error\") {\n super(message);\n this.name = 'QueueError';\n this.code = code;\n }\n}\n\n/**\n * Events emitted by the Queue.\n */\nexport interface QueueEvents {\n /**\n * Fired when a worker is added.\n * @param workerName Name of the worker.\n */\n workerAdded: (workerName: string) => void;\n\n /**\n * Fired when a job is added to the queue.\n * @param job The RawJob that was added.\n */\n jobAdded: (job: RawJob) => void;\n\n /**\n * Fired when a job starts processing.\n * @param job The RawJob that started.\n */\n jobStarted: (job: RawJob) => void;\n\n /**\n * Fired when a job completes successfully.\n * @param job The Job with payload that succeeded.\n */\n jobSucceeded: (job: Job) => void;\n\n /**\n * Fired when a job fails.\n * @param job The RawJob that failed.\n * @param error The error thrown.\n */\n jobFailed: (job: RawJob, error: Error) => void;\n\n /**\n * Fired when a job fails.\n * @param job The RawJob that failed.\n * @param error The error thrown.\n */\n jobCancelled: (job: RawJob) => void;\n\n /**\n * Fired when a job completes (regardless of success or failure).\n * @param job The RawJob that finished.\n */\n jobCompleted: (job: RawJob) => void;\n\n jobDeleted: (job: RawJob) => void\n}\n\n\n/**\n * Options to configure the queue\n */\nexport interface QueueOptions {\n /**\n * A callback function which is called after the queue has been stopped\n * @parameter executedJobs\n */\n onQueueFinish?: (executedJobs: Array>) => void;\n /**\n * Interval in which the queue checks for new jobs to execute\n */\n updateInterval?: number;\n concurrency?: number;\n}\n/**\n * ## Usage\n *\n * ```typescript\n * import queue from 'react-native-job-queue'\n *\n * queue.configure({onQueueFinish:(executedJobs:Job[])=>{\n * console.log(\"Queue stopped and executed\",executedJobs)\n * }});\n * queue.addWorker(new Worker(\"testWorker\",async(payload, id)=>{\n * return new Promise((resolve) => {\n * setTimeout(() => {\n * console.log('Executing jobId', id, 'with:', payload.text);\n * resolve();\n * }, payload.delay);});\n * }))\n * queue.addJob(\"testWorker\",{text:\"Job example payload content text\",delay:5000})\n * ```\n */\nexport class Queue extends EventEmitter {\n static get instance() {\n if (this.queueInstance) {\n return this.queueInstance;\n } else {\n this.queueInstance = new Queue();\n return this.queueInstance;\n }\n }\n /**\n * @returns true if the Queue is running and false otherwise\n */\n get isRunning() {\n return this.isActive;\n }\n /**\n * @returns the workers map (readonly)\n */\n get registeredWorkers() {\n return this.workers;\n }\n private static queueInstance: Queue | null;\n private emitter: EventEmitter = new EventEmitter();\n\n private jobStore: JobStore;\n private workers: { [key: string]: Worker };\n private isActive: boolean;\n\n private timeoutId: number;\n private executedJobs: Array>;\n private activeJobCount: number;\n\n private concurrency: number;\n private updateInterval: number;\n private onQueueFinish: (executedJobs: Array>) => void;\n\n private queuedJobExecuter: any[] = [];\n private runningJobPromises: { [key: string]: CancellablePromise };\n\n private constructor() {\n super();\n this.jobStore = NativeModules.JobQueue;\n this.workers = {};\n this.runningJobPromises = {};\n this.isActive = false;\n\n this.timeoutId = 0;\n this.executedJobs = [];\n this.activeJobCount = 0;\n\n this.updateInterval = 10;\n this.onQueueFinish = (executedJobs: Array>) => { };\n this.concurrency = -1;\n }\n\n\n\n /**\n * @returns a promise that resolves all jobs of jobStore\n */\n async getJobs() {\n return await this.jobStore.getJobs();\n }\n async getJobsWithDeleted() {\n return await this.jobStore.getJobsWithDeleted();\n }\n /**\n * @param job the job to be deleted\n */\n removeJob(job: RawJob) {\n this.jobStore.removeJob(job);\n this.emit(\"jobDeleted\", job)\n }\n removeJobPermanent(job: RawJob) {\n this.jobStore.removeJobPermanently(job);\n this.emit(\"jobDeleted\", job)\n }\n /**\n * @param job the job which should be requeued\n */\n requeueJob(job: RawJob) {\n this.jobStore.updateJob({ ...job, failed: '', status: \"idle\", active: TRUE });\n\n if (!this.isActive) {\n // eslint-disable-next-line @typescript-eslint/ban-ts-comment\n // @ts-ignore\n this.start().then(() => {\n console.log(\"Queue restarted\")\n }).catch(() => {\n console.log(\"Queue could not be restarted\")\n });\n }\n }\n\n configure(options: QueueOptions) {\n const {\n onQueueFinish = (executedJobs: Array>) => { },\n updateInterval = 10,\n concurrency = -1,\n } = options;\n this.onQueueFinish = onQueueFinish;\n this.updateInterval = updateInterval;\n this.concurrency = concurrency;\n }\n /**\n * adds a [[Worker]] to the queue which can execute Jobs\n * @param worker\n */\n addWorker(worker: Worker) {\n if (this.workers[worker.name]) {\n throw new QueueError(`Worker \"${worker.name}\" already exists.`, \"error\");\n }\n this.workers[worker.name] = worker;\n this.emit('workerAdded', worker.name);\n }\n\n /**\n * removes worker from queue\n *\n * @param name\n * @param [deleteRelatedJobs=false] removes all queued jobs releated to the worker if set to true\n */\n removeWorker(name: string, deleteRelatedJobs = false) {\n delete this.workers[name];\n if (deleteRelatedJobs) {\n this.jobStore.removeJobsByWorkerName(name);\n }\n }\n\n /**\n * adds a job to the queue\n * @param workerName name of the worker which should be used to excute the job\n * @param [payload={}] payload which is passed as parameter to the executer\n * @param [options={ attempts: 0, timeout: 0, priority: 0 }] options to set max attempts, a timeout and a priority\n * @param [startQueue=true] if set to false the queue won't start automaticly when adding a job\n * @returns job id\n */\n addJob

(\n workerName: string,\n payload: P,\n options = { attempts: 0, timeout: 0, priority: 0 },\n startQueue = true\n ) {\n const { attempts = 0, timeout = 0, priority = 0 } = options;\n const id: string = Uuid.v4();\n const job: RawJob = {\n id,\n payload: JSON.stringify(payload || {}),\n metaData: JSON.stringify({ failedAttempts: 0, errors: [] }),\n active: FALSE,\n created: new Date().toISOString(),\n failed: '',\n workerName,\n attempts,\n timeout,\n priority,\n isDeleted: false,\n status: \"idle\"\n };\n if (!this.workers[job.workerName]) {\n throw new QueueError(`Missing worker with name ${job.workerName}`);\n }\n\n this.jobStore.addJob(job);\n this.emit('jobAdded', job);\n if (startQueue && !this.isActive) {\n this.start();\n }\n\n return id;\n }\n /**\n * starts the queue to execute queued jobs\n */\n async start() {\n if (!this.isActive) {\n this.isActive = true;\n this.executedJobs = [];\n await this.resetActiveJobs();\n this.scheduleQueue();\n }\n }\n /**\n * stop the queue from executing queued jobs\n */\n stop() {\n this.isActive = false;\n }\n\n /**\n * cancel running job\n */\n cancelJob(jobId: string, exception?: Error) {\n const promise = this.runningJobPromises[jobId];\n if (promise !== undefined && typeof promise[CANCEL] === 'function') {\n promise[CANCEL](exception || new QueueError(`job canceled`, \"cancelled\"));\n } else if (!promise[CANCEL]) {\n console.warn('Worker does not have a cancel method implemented');\n } else {\n throw new QueueError(`Job with id ${jobId} not currently running`, \"error\");\n }\n }\n async cancelAllActiveJobs() {\n const jobs = await this.jobStore.getActiveMarkedJobs()\n\n jobs.forEach((job) => {\n const newJob = { ...job, ...{ active: FALSE, status: \"cancelled\" } };\n const isRunning = this.runningJobPromises[job.id];\n // eslint-disable-next-line @typescript-eslint/no-misused-promises\n if (!!Boolean(isRunning)) {\n this.cancelJob(job.id, new QueueError(`Job with id ${job.id} cancelled`, \"cancelled\"));\n }\n this.jobStore.updateJob(newJob as RawJob);\n this.emit('jobCancelled', newJob as RawJob);\n })\n }\n cancelActiveJob(job: RawJob) {\n const newJob = { ...job, ...{ active: FALSE, status: \"cancelled\" } };\n\n const isRunning = this.runningJobPromises[job.id];\n // eslint-disable-next-line @typescript-eslint/no-misused-promises\n if (!!isRunning) {\n this.cancelJob(job.id, new QueueError(`Job with id ${job.id} cancelled`, \"cancelled\"));\n }\n\n this.jobStore.updateJob(newJob as RawJob);\n\n this.emit('jobCancelled', newJob as RawJob);\n }\n\n private resetActiveJob = (job: RawJob) => {\n this.jobStore.updateJob({ ...job, ...{ active: FALSE } });\n };\n private async resetActiveJobs() {\n const activeMarkedJobs = await this.jobStore.getActiveMarkedJobs();\n const resetTasks = activeMarkedJobs.map(this.resetActiveJob);\n await Promise.all(resetTasks);\n }\n private scheduleQueue() {\n if (AppState.currentState === 'active' && Platform.OS === \"ios\") {\n this.timeoutId = setTimeout(this.runQueue, this.updateInterval);\n } else {\n this.runQueue();\n }\n }\n private runQueue = async () => {\n if (!this.isActive) {\n this.finishQueue();\n return;\n }\n const nextJob = await this.jobStore.getNextJob();\n if (this.isJobNotEmpty(nextJob)) {\n const nextJobs = await this.getJobsForWorker(nextJob.workerName);\n const processingJobs = nextJobs.map(async (job) => this.limitExecution(this.excuteJob, job));\n await Promise.all(processingJobs);\n } else if (!this.isExecuting()) {\n this.finishQueue();\n return;\n }\n this.scheduleQueue();\n };\n\n private isJobNotEmpty(rawJob: RawJob | {}) {\n return Object.keys(rawJob).length > 0;\n }\n\n private limitExecution = async (executer: (rawJob: RawJob) => Promise, rawJob: RawJob) => {\n return new Promise(async (resolve) => await this.enqueueJobExecuter(executer, resolve, rawJob));\n };\n\n private enqueueJobExecuter = async (\n executer: (rawJob: RawJob) => Promise,\n resolve: (_: unknown) => void,\n rawJob: RawJob\n ) => {\n if (this.isExecuterAvailable()) {\n await this.runExecuter(executer, resolve, rawJob);\n } else {\n this.queuedJobExecuter.push(this.runExecuter.bind(null, executer, resolve, rawJob));\n }\n };\n\n private runExecuter = async (\n executer: (rawJob: RawJob) => Promise,\n resolve: (_: unknown) => void,\n rawJob: RawJob\n ) => {\n try {\n await executer(rawJob);\n } finally {\n resolve(true);\n if (this.queuedJobExecuter.length > 0 && this.isExecuterAvailable()) {\n await this.queuedJobExecuter.shift()();\n }\n }\n };\n private isExecuterAvailable() {\n return this.concurrency <= 0 || this.activeJobCount < this.concurrency;\n }\n private isExecuting() {\n return this.activeJobCount > 0;\n }\n\n private finishQueue() {\n this.onQueueFinish(this.executedJobs);\n this.isActive = false;\n clearTimeout(this.timeoutId);\n }\n\n async getJobsForWorker(workerName: string) {\n const { isBusy, availableExecuters } = this.workers[workerName];\n if (!isBusy) {\n return await this.jobStore.getJobsForWorker(workerName, availableExecuters);\n } else {\n return await this.getJobsForAlternateWorker();\n }\n }\n\n async getJobsForWorkerWithDeleted(workerName: string) {\n const { isBusy, availableExecuters } = this.workers[workerName];\n if (!isBusy) {\n return await this.jobStore.getJobsForWorkerWithDeleted(workerName, availableExecuters);\n } else {\n return await this.getJobsForAlternateWorker();\n }\n }\n\n private async getJobsForAlternateWorker() {\n for (const workerName of Object.keys(this.workers)) {\n const { isBusy, availableExecuters } = this.workers[workerName];\n let nextJobs: RawJob[] = [];\n if (!isBusy) {\n nextJobs = await this.jobStore.getJobsForWorker(workerName, availableExecuters);\n }\n if (nextJobs.length > 0) {\n return nextJobs;\n }\n }\n return [];\n }\n\n private excuteJob = async (rawJob: RawJob) => {\n const worker = this.workers[rawJob.workerName];\n const payload = JSON.parse(rawJob.payload) as Worker;\n const job = { ...rawJob, ...{ payload } } as Job;\n\n try {\n job.status = \"processing\";\n this.jobStore.updateJob({ ...job, payload: JSON.stringify(payload) });\n this.emit('jobStarted', job);\n\n this.activeJobCount++;\n if (!this.workers[rawJob.workerName]) {\n throw new QueueError(`Missing worker with name ${rawJob.workerName}`, \"error\");\n }\n const promise = worker.execute(rawJob);\n\n this.runningJobPromises[rawJob.id] = promise;\n await promise;\n\n worker.triggerSuccess(job);\n job.status = \"finished\";\n this.jobStore.updateJob({ ...job, payload: JSON.stringify(payload) });\n this.jobStore.removeJob(rawJob);\n this.emit('jobSucceeded', job);\n } catch (err) {\n const error = err as QueueError;\n const { attempts } = rawJob;\n // eslint-disable-next-line prefer-const\n let { errors, failedAttempts } = JSON.parse(rawJob.metaData) as { errors: string[]; failedAttempts: number };\n failedAttempts++;\n let failed = '';\n if (failedAttempts >= attempts) {\n failed = new Date().toISOString();\n }\n const metaData = JSON.stringify({ errors: [...errors, error], failedAttempts });\n worker.triggerFailure({ ...job, metaData, failed }, error);\n const failedJob = { ...rawJob, ...{ active: FALSE, metaData, failed, status: error.code === \"cancelled\" ? \"cancelled\" : \"failed\" } } as RawJob;\n this.jobStore.updateJob(failedJob);\n this.emit('jobFailed', failedJob, error);\n } finally {\n delete this.runningJobPromises[job.id];\n worker.decreaseExecutionCount();\n worker.triggerCompletion(job);\n this.emit('jobCompleted', { ...job });\n this.executedJobs.push(rawJob);\n this.activeJobCount--;\n }\n };\n}\nexport default Queue.instance;\n" - ], - "mappings": ";;;;;;AAEA,IAAAA,YAAA,GAAAC,OAAA;AAEA,IAAAC,IA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AAC,CAAC;IACjD;EACJ;EAEA,MAAMC,2BAA2BA,CAAC5G,UAAkB,EAAE;IAClD,MAAM;MAAEyG,MAAM;MAAEC;IAAmB,CAAC,GAAG,IAAI,CAACtH,OAAO,CAACY,UAAU,CAAC;IAC/D,IAAI,CAACyG,MAAM,EAAE;MACT,OAAO,MAAM,IAAI,CAACnH,QAAQ,CAACsH,2BAA2B,CAAC5G,UAAU,EAAE0G,kBAAkB,CAAC;IAC1F,CAAC,MAAM;MACH,OAAO,MAAM,IAAI,CAACC,yBAAyB,CAAC,CAAC;IACjD;EACJ;EAEA,MAAcA,yBAAyBA,CAAA,EAAG;IACtC,KAAK,MAAM3G,UAAU,IAAIxC,MAAM,CAAC+I,IAAI,CAAC,IAAI,CAACnH,OAAO,CAAC,EAAE;MAChD,MAAM;QAAEqH,MAAM;QAAEC;MAAmB,CAAC,GAAG,IAAI,CAACtH,OAAO,CAACY,UAAU,CAAC;MAC/D,IAAIF,QAAkB,GAAG,EAAE;MAC3B,IAAI,CAAC2G,MAAM,EAAE;QACT3G,QAAQ,GAAG,MAAM,IAAI,CAACR,QAAQ,CAACS,gBAAgB,CAACC,UAAU,EAAE0G,kBAAkB,CAAC;MACnF;MACA,IAAI5G,QAAQ,CAACoB,MAAM,GAAG,CAAC,EAAE;QACrB,OAAOpB,QAAQ;MACnB;IACJ;IACA,OAAO,EAAE;EACb;AAkDJ;AAAClB,OAAA,CAAAC,KAAA,GAAAA,KAAA;AAAA7B,MAAA,GArYY6B,KAAK;AAAAzB,eAAA,CAALyB,KAAK;AAAA,IAAAgI,QAAA,GAAAjI,OAAA,CAAAzB,OAAA,GAsYH0B,KAAK,CAACE,QAAQ", - "ignoreList": [] -} \ No newline at end of file +{"version":3,"names":["_reactNative","require","_Job","_Uuid","_Worker","_eventemitter","_interopRequireDefault","_Queue","e","__esModule","default","_defineProperty","r","t","_toPropertyKey","Object","defineProperty","value","enumerable","configurable","writable","i","_toPrimitive","Symbol","toPrimitive","call","TypeError","String","Number","QueueError","Error","constructor","message","code","name","exports","Queue","EventEmitter","instance","queueInstance","isRunning","isActive","registeredWorkers","workers","job","jobStore","updateJob","active","FALSE","finishQueue","nextJob","getNextJob","isJobNotEmpty","nextJobs","getJobsForWorker","workerName","processingJobs","map","limitExecution","excuteJob","Promise","all","isExecuting","scheduleQueue","executer","rawJob","resolve","enqueueJobExecuter","isExecuterAvailable","runExecuter","queuedJobExecuter","push","bind","length","shift","worker","payload","JSON","parse","status","stringify","emit","activeJobCount","promise","execute","runningJobPromises","id","triggerSuccess","removeJob","err","error","attempts","errors","failedAttempts","metaData","failed","Date","toISOString","triggerFailure","failedJob","decreaseExecutionCount","triggerCompletion","executedJobs","NativeModules","JobQueue","timeoutId","updateInterval","onQueueFinish","concurrency","getJobs","getJobsWithDeleted","removeJobPermanent","removeJobPermanently","requeueJob","TRUE","start","then","console","log","catch","configure","options","addWorker","removeWorker","deleteRelatedJobs","removeJobsByWorkerName","addJob","timeout","priority","startQueue","Uuid","v4","created","isDeleted","resetActiveJobs","stop","cancelJob","jobId","exception","undefined","CANCEL","warn","cancelAllActiveJobs","jobs","getActiveMarkedJobs","forEach","newJob","Boolean","cancelActiveJob","activeMarkedJobs","resetTasks","resetActiveJob","AppState","currentState","Platform","OS","setTimeout","runQueue","keys","clearTimeout","isBusy","availableExecuters","getJobsForAlternateWorker","getJobsForWorkerWithDeleted","_default"],"sources":["Queue.ts"],"sourcesContent":["/* eslint-disable no-extra-boolean-cast */\n/* eslint-disable @typescript-eslint/no-empty-function */\nimport { AppState, NativeModules, Platform } from 'react-native';\n\nimport { FALSE, Job, RawJob, TRUE } from './models/Job';\nimport { JobStore } from './models/JobStore';\nimport { Uuid } from './utils/Uuid';\nimport { Worker, CANCEL, CancellablePromise } from './Worker';\n\n\nimport EventEmitter from 'eventemitter3';\n\ntype QueueErrorType = \"cancelled\" | \"error\";\n\nexport class QueueError extends Error {\n code: QueueErrorType;\n constructor(message: string, code: QueueErrorType = \"error\") {\n super(message);\n this.name = 'QueueError';\n this.code = code;\n }\n}\n\n/**\n * Events emitted by the Queue.\n */\nexport interface QueueEvents {\n /**\n * Fired when a worker is added.\n * @param workerName Name of the worker.\n */\n workerAdded: (workerName: string) => void;\n\n /**\n * Fired when a job is added to the queue.\n * @param job The RawJob that was added.\n */\n jobAdded: (job: RawJob) => void;\n\n /**\n * Fired when a job starts processing.\n * @param job The RawJob that started.\n */\n jobStarted: (job: RawJob) => void;\n\n /**\n * Fired when a job completes successfully.\n * @param job The Job with payload that succeeded.\n */\n jobSucceeded: (job: Job) => void;\n\n /**\n * Fired when a job fails.\n * @param job The RawJob that failed.\n * @param error The error thrown.\n */\n jobFailed: (job: RawJob, error: Error) => void;\n\n /**\n * Fired when a job fails.\n * @param job The RawJob that failed.\n * @param error The error thrown.\n */\n jobCancelled: (job: RawJob) => void;\n\n /**\n * Fired when a job completes (regardless of success or failure).\n * @param job The RawJob that finished.\n */\n jobCompleted: (job: RawJob) => void;\n\n jobDeleted: (job: RawJob) => void\n}\n\n\n/**\n * Options to configure the queue\n */\nexport interface QueueOptions {\n /**\n * A callback function which is called after the queue has been stopped\n * @parameter executedJobs\n */\n onQueueFinish?: (executedJobs: Array>) => void;\n /**\n * Interval in which the queue checks for new jobs to execute\n */\n updateInterval?: number;\n concurrency?: number;\n}\n/**\n * ## Usage\n *\n * ```typescript\n * import queue from 'react-native-job-queue'\n *\n * queue.configure({onQueueFinish:(executedJobs:Job[])=>{\n * console.log(\"Queue stopped and executed\",executedJobs)\n * }});\n * queue.addWorker(new Worker(\"testWorker\",async(payload, id)=>{\n * return new Promise((resolve) => {\n * setTimeout(() => {\n * console.log('Executing jobId', id, 'with:', payload.text);\n * resolve();\n * }, payload.delay);});\n * }))\n * queue.addJob(\"testWorker\",{text:\"Job example payload content text\",delay:5000})\n * ```\n */\nexport class Queue extends EventEmitter {\n static get instance() {\n if (this.queueInstance) {\n return this.queueInstance;\n } else {\n this.queueInstance = new Queue();\n return this.queueInstance;\n }\n }\n /**\n * @returns true if the Queue is running and false otherwise\n */\n get isRunning() {\n return this.isActive;\n }\n /**\n * @returns the workers map (readonly)\n */\n get registeredWorkers() {\n return this.workers;\n }\n private static queueInstance: Queue | null;\n private emitter: EventEmitter = new EventEmitter();\n\n private jobStore: JobStore;\n private workers: { [key: string]: Worker };\n private isActive: boolean;\n\n private timeoutId: number;\n private executedJobs: Array>;\n private activeJobCount: number;\n\n private concurrency: number;\n private updateInterval: number;\n private onQueueFinish: (executedJobs: Array>) => void;\n\n private queuedJobExecuter: any[] = [];\n private runningJobPromises: { [key: string]: CancellablePromise };\n\n private constructor() {\n super();\n this.jobStore = NativeModules.JobQueue;\n this.workers = {};\n this.runningJobPromises = {};\n this.isActive = false;\n\n this.timeoutId = 0;\n this.executedJobs = [];\n this.activeJobCount = 0;\n\n this.updateInterval = 10;\n this.onQueueFinish = (executedJobs: Array>) => { };\n this.concurrency = -1;\n }\n\n\n\n /**\n * @returns a promise that resolves all jobs of jobStore\n */\n async getJobs() {\n return await this.jobStore.getJobs();\n }\n async getJobsWithDeleted() {\n return await this.jobStore.getJobsWithDeleted();\n }\n /**\n * @param job the job to be deleted\n */\n removeJob(job: RawJob) {\n this.jobStore.removeJob(job);\n this.emit(\"jobDeleted\", job)\n }\n removeJobPermanent(job: RawJob) {\n this.jobStore.removeJobPermanently(job);\n this.emit(\"jobDeleted\", job)\n }\n /**\n * @param job the job which should be requeued\n */\n requeueJob(job: RawJob) {\n this.jobStore.updateJob({ ...job, failed: '', status: \"idle\", active: TRUE });\n\n if (!this.isActive) {\n // eslint-disable-next-line @typescript-eslint/ban-ts-comment\n // @ts-ignore\n this.start().then(() => {\n console.log(\"Queue restarted\")\n }).catch(() => {\n console.log(\"Queue could not be restarted\")\n });\n }\n }\n\n configure(options: QueueOptions) {\n const {\n onQueueFinish = (executedJobs: Array>) => { },\n updateInterval = 10,\n concurrency = -1,\n } = options;\n this.onQueueFinish = onQueueFinish;\n this.updateInterval = updateInterval;\n this.concurrency = concurrency;\n }\n /**\n * adds a [[Worker]] to the queue which can execute Jobs\n * @param worker\n */\n addWorker(worker: Worker) {\n if (this.workers[worker.name]) {\n throw new QueueError(`Worker \"${worker.name}\" already exists.`, \"error\");\n }\n this.workers[worker.name] = worker;\n this.emit('workerAdded', worker.name);\n }\n\n /**\n * removes worker from queue\n *\n * @param name\n * @param [deleteRelatedJobs=false] removes all queued jobs releated to the worker if set to true\n */\n removeWorker(name: string, deleteRelatedJobs = false) {\n delete this.workers[name];\n if (deleteRelatedJobs) {\n this.jobStore.removeJobsByWorkerName(name);\n }\n }\n\n /**\n * adds a job to the queue\n * @param workerName name of the worker which should be used to excute the job\n * @param [payload={}] payload which is passed as parameter to the executer\n * @param [options={ attempts: 0, timeout: 0, priority: 0 }] options to set max attempts, a timeout and a priority\n * @param [startQueue=true] if set to false the queue won't start automaticly when adding a job\n * @returns job id\n */\n addJob

(\n workerName: string,\n payload: P,\n options = { attempts: 0, timeout: 0, priority: 0 },\n startQueue = true\n ) {\n const { attempts = 0, timeout = 0, priority = 0 } = options;\n const id: string = Uuid.v4();\n const job: RawJob = {\n id,\n payload: JSON.stringify(payload || {}),\n metaData: JSON.stringify({ failedAttempts: 0, errors: [] }),\n active: FALSE,\n created: new Date().toISOString(),\n failed: '',\n workerName,\n attempts,\n timeout,\n priority,\n isDeleted: false,\n status: \"idle\"\n };\n if (!this.workers[job.workerName]) {\n throw new QueueError(`Missing worker with name ${job.workerName}`);\n }\n\n this.jobStore.addJob(job);\n this.emit('jobAdded', job);\n if (startQueue && !this.isActive) {\n this.start();\n }\n\n return id;\n }\n /**\n * starts the queue to execute queued jobs\n */\n async start() {\n if (!this.isActive) {\n this.isActive = true;\n this.executedJobs = [];\n await this.resetActiveJobs();\n this.scheduleQueue();\n }\n }\n /**\n * stop the queue from executing queued jobs\n */\n stop() {\n this.isActive = false;\n }\n\n /**\n * cancel running job\n */\n cancelJob(jobId: string, exception?: Error) {\n const promise = this.runningJobPromises[jobId];\n if (promise !== undefined && typeof promise[CANCEL] === 'function') {\n promise[CANCEL](exception || new QueueError(`job canceled`, \"cancelled\"));\n } else if (!promise[CANCEL]) {\n console.warn('Worker does not have a cancel method implemented');\n } else {\n throw new QueueError(`Job with id ${jobId} not currently running`, \"error\");\n }\n }\n async cancelAllActiveJobs() {\n const jobs = await this.jobStore.getActiveMarkedJobs()\n\n jobs.forEach((job) => {\n const newJob = { ...job, ...{ active: FALSE, status: \"cancelled\" } };\n const isRunning = this.runningJobPromises[job.id];\n // eslint-disable-next-line @typescript-eslint/no-misused-promises\n if (!!Boolean(isRunning)) {\n this.cancelJob(job.id, new QueueError(`Job with id ${job.id} cancelled`, \"cancelled\"));\n }\n this.jobStore.updateJob(newJob as RawJob);\n this.emit('jobCancelled', newJob as RawJob);\n })\n }\n cancelActiveJob(job: RawJob) {\n const newJob = { ...job, ...{ active: FALSE, status: \"cancelled\" } };\n\n const isRunning = this.runningJobPromises[job.id];\n // eslint-disable-next-line @typescript-eslint/no-misused-promises\n if (!!isRunning) {\n this.cancelJob(job.id, new QueueError(`Job with id ${job.id} cancelled`, \"cancelled\"));\n }\n\n this.jobStore.updateJob(newJob as RawJob);\n\n this.emit('jobCancelled', newJob as RawJob);\n }\n\n private resetActiveJob = (job: RawJob) => {\n this.jobStore.updateJob({ ...job, ...{ active: FALSE } });\n };\n private async resetActiveJobs() {\n const activeMarkedJobs = await this.jobStore.getActiveMarkedJobs();\n const resetTasks = activeMarkedJobs.map(this.resetActiveJob);\n await Promise.all(resetTasks);\n }\n private scheduleQueue() {\n if (AppState.currentState === 'active' && Platform.OS === \"ios\") {\n this.timeoutId = setTimeout(this.runQueue, this.updateInterval);\n } else {\n this.runQueue();\n }\n }\n private runQueue = async () => {\n if (!this.isActive) {\n this.finishQueue();\n return;\n }\n const nextJob = await this.jobStore.getNextJob();\n if (this.isJobNotEmpty(nextJob)) {\n const nextJobs = await this.getJobsForWorker(nextJob.workerName);\n const processingJobs = nextJobs.map(async (job) => this.limitExecution(this.excuteJob, job));\n await Promise.all(processingJobs);\n } else if (!this.isExecuting()) {\n this.finishQueue();\n return;\n }\n this.scheduleQueue();\n };\n\n private isJobNotEmpty(rawJob: RawJob | {}) {\n return Object.keys(rawJob).length > 0;\n }\n\n private limitExecution = async (executer: (rawJob: RawJob) => Promise, rawJob: RawJob) => {\n return new Promise(async (resolve) => await this.enqueueJobExecuter(executer, resolve, rawJob));\n };\n\n private enqueueJobExecuter = async (\n executer: (rawJob: RawJob) => Promise,\n resolve: (_: unknown) => void,\n rawJob: RawJob\n ) => {\n if (this.isExecuterAvailable()) {\n await this.runExecuter(executer, resolve, rawJob);\n } else {\n this.queuedJobExecuter.push(this.runExecuter.bind(null, executer, resolve, rawJob));\n }\n };\n\n private runExecuter = async (\n executer: (rawJob: RawJob) => Promise,\n resolve: (_: unknown) => void,\n rawJob: RawJob\n ) => {\n try {\n await executer(rawJob);\n } finally {\n resolve(true);\n if (this.queuedJobExecuter.length > 0 && this.isExecuterAvailable()) {\n await this.queuedJobExecuter.shift()();\n }\n }\n };\n private isExecuterAvailable() {\n return this.concurrency <= 0 || this.activeJobCount < this.concurrency;\n }\n private isExecuting() {\n return this.activeJobCount > 0;\n }\n\n private finishQueue() {\n this.onQueueFinish(this.executedJobs);\n this.isActive = false;\n clearTimeout(this.timeoutId);\n }\n\n async getJobsForWorker(workerName: string) {\n const { isBusy, availableExecuters } = this.workers[workerName];\n if (!isBusy) {\n return await this.jobStore.getJobsForWorker(workerName, availableExecuters);\n } else {\n return await this.getJobsForAlternateWorker();\n }\n }\n\n async getJobsForWorkerWithDeleted(workerName: string) {\n const { isBusy, availableExecuters } = this.workers[workerName];\n if (!isBusy) {\n return await this.jobStore.getJobsForWorkerWithDeleted(workerName, availableExecuters);\n } else {\n return await this.getJobsForAlternateWorker();\n }\n }\n\n private async getJobsForAlternateWorker() {\n for (const workerName of Object.keys(this.workers)) {\n const { isBusy, availableExecuters } = this.workers[workerName];\n let nextJobs: RawJob[] = [];\n if (!isBusy) {\n nextJobs = await this.jobStore.getJobsForWorker(workerName, availableExecuters);\n }\n if (nextJobs.length > 0) {\n return nextJobs;\n }\n }\n return [];\n }\n\n private excuteJob = async (rawJob: RawJob) => {\n const worker = this.workers[rawJob.workerName];\n const payload = JSON.parse(rawJob.payload) as Worker;\n const job = { ...rawJob, ...{ payload } } as Job;\n\n try {\n job.status = \"processing\";\n this.jobStore.updateJob({ ...job, payload: JSON.stringify(payload) });\n this.emit('jobStarted', job);\n\n this.activeJobCount++;\n if (!this.workers[rawJob.workerName]) {\n throw new QueueError(`Missing worker with name ${rawJob.workerName}`, \"error\");\n }\n const promise = worker.execute(rawJob);\n\n this.runningJobPromises[rawJob.id] = promise;\n await promise;\n\n worker.triggerSuccess(job);\n job.status = \"finished\";\n this.jobStore.updateJob({ ...job, payload: JSON.stringify(payload) });\n this.jobStore.removeJob(rawJob);\n this.emit('jobSucceeded', job);\n } catch (err) {\n const error = err as QueueError;\n const { attempts } = rawJob;\n // eslint-disable-next-line prefer-const\n let { errors, failedAttempts } = JSON.parse(rawJob.metaData) as { errors: string[]; failedAttempts: number };\n failedAttempts++;\n let failed = '';\n if (failedAttempts >= attempts) {\n failed = new Date().toISOString();\n }\n const metaData = JSON.stringify({ errors: [...errors, error], failedAttempts });\n worker.triggerFailure({ ...job, metaData, failed }, error);\n const failedJob = { ...rawJob, ...{ active: FALSE, metaData, failed, status: error.code === \"cancelled\" ? \"cancelled\" : \"failed\" } } as RawJob;\n this.jobStore.updateJob(failedJob);\n this.emit('jobFailed', failedJob, error);\n } finally {\n delete this.runningJobPromises[job.id];\n worker.decreaseExecutionCount();\n worker.triggerCompletion(job);\n this.emit('jobCompleted', { ...job });\n this.executedJobs.push(rawJob);\n this.activeJobCount--;\n }\n };\n}\nexport default Queue.instance;\n"],"mappings":";;;;;;AAEA,IAAAA,YAAA,GAAAC,OAAA;AAEA,IAAAC,IAAA,GAAAD,OAAA;AAEA,IAAAE,KAAA,GAAAF,OAAA;AACA,IAAAG,OAAA,GAAAH,OAAA;AAGA,IAAAI,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MAAEC;IAAmB,CAAC,GAAG,IAAI,CAACtH,OAAO,CAACY,UAAU,CAAC;IAC/D,IAAI,CAACyG,MAAM,EAAE;MACT,OAAO,MAAM,IAAI,CAACnH,QAAQ,CAACsH,2BAA2B,CAAC5G,UAAU,EAAE0G,kBAAkB,CAAC;IAC1F,CAAC,MAAM;MACH,OAAO,MAAM,IAAI,CAACC,yBAAyB,CAAC,CAAC;IACjD;EACJ;EAEA,MAAcA,yBAAyBA,CAAA,EAAG;IACtC,KAAK,MAAM3G,UAAU,IAAIxC,MAAM,CAAC+I,IAAI,CAAC,IAAI,CAACnH,OAAO,CAAC,EAAE;MAChD,MAAM;QAAEqH,MAAM;QAAEC;MAAmB,CAAC,GAAG,IAAI,CAACtH,OAAO,CAACY,UAAU,CAAC;MAC/D,IAAIF,QAAkB,GAAG,EAAE;MAC3B,IAAI,CAAC2G,MAAM,EAAE;QACT3G,QAAQ,GAAG,MAAM,IAAI,CAACR,QAAQ,CAACS,gBAAgB,CAACC,UAAU,EAAE0G,kBAAkB,CAAC;MACnF;MACA,IAAI5G,QAAQ,CAACoB,MAAM,GAAG,CAAC,EAAE;QACrB,OAAOpB,QAAQ;MACnB;IACJ;IACA,OAAO,EAAE;EACb;AAkDJ;AAAClB,OAAA,CAAAC,KAAA,GAAAA,KAAA;AAAA7B,MAAA,GArYY6B,KAAK;AAAAzB,eAAA,CAALyB,KAAK;AAAA,IAAAgI,QAAA,GAAAjI,OAAA,CAAAzB,OAAA,GAsYH0B,KAAK,CAACE,QAAQ","ignoreList":[]} \ No newline at end of file diff --git a/lib/module/Queue.js b/lib/module/Queue.js index 212ddb2..c1ff00f 100644 --- a/lib/module/Queue.js +++ b/lib/module/Queue.js @@ -1,26 +1,7 @@ var _Queue; -function _defineProperty(e, r, t) { - return ( - (r = _toPropertyKey(r)) in e - ? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 }) - : (e[r] = t), - e - ); -} -function _toPropertyKey(t) { - var i = _toPrimitive(t, 'string'); - return 'symbol' == typeof i ? i : i + ''; -} -function _toPrimitive(t, r) { - if ('object' != typeof t || !t) return t; - var e = t[Symbol.toPrimitive]; - if (void 0 !== e) { - var i = e.call(t, r || 'default'); - if ('object' != typeof i) return i; - throw new TypeError('@@toPrimitive must return a primitive value.'); - } - return ('string' === r ? String : Number)(t); -} +function _defineProperty(e, r, t) { return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : e[r] = t, e; } +function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == typeof i ? i : i + ""; } +function _toPrimitive(t, r) { if ("object" != typeof t || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != typeof i) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); } /* eslint-disable no-extra-boolean-cast */ /* eslint-disable @typescript-eslint/no-empty-function */ import { AppState, NativeModules, Platform } from 'react-native'; @@ -29,12 +10,12 @@ import { Uuid } from './utils/Uuid'; import { CANCEL } from './Worker'; import EventEmitter from 'eventemitter3'; export class QueueError extends Error { - constructor(message, code = 'error') { - super(message); - _defineProperty(this, 'code', void 0); - this.name = 'QueueError'; - this.code = code; - } + constructor(message, code = "error") { + super(message); + _defineProperty(this, "code", void 0); + this.name = 'QueueError'; + this.code = code; + } } /** @@ -65,414 +46,426 @@ export class QueueError extends Error { * ``` */ export class Queue extends EventEmitter { - static get instance() { - if (this.queueInstance) { - return this.queueInstance; - } else { - this.queueInstance = new Queue(); - return this.queueInstance; - } + static get instance() { + if (this.queueInstance) { + return this.queueInstance; + } else { + this.queueInstance = new Queue(); + return this.queueInstance; } - /** - * @returns true if the Queue is running and false otherwise - */ - get isRunning() { - return this.isActive; - } - /** - * @returns the workers map (readonly) - */ - get registeredWorkers() { - return this.workers; - } - constructor() { - super(); - _defineProperty(this, 'emitter', new EventEmitter()); - _defineProperty(this, 'jobStore', void 0); - _defineProperty(this, 'workers', void 0); - _defineProperty(this, 'isActive', void 0); - _defineProperty(this, 'timeoutId', void 0); - _defineProperty(this, 'executedJobs', void 0); - _defineProperty(this, 'activeJobCount', void 0); - _defineProperty(this, 'concurrency', void 0); - _defineProperty(this, 'updateInterval', void 0); - _defineProperty(this, 'onQueueFinish', void 0); - _defineProperty(this, 'queuedJobExecuter', []); - _defineProperty(this, 'runningJobPromises', void 0); - _defineProperty(this, 'resetActiveJob', (job) => { - this.jobStore.updateJob({ - ...job, - ...{ - active: FALSE, - }, - }); - }); - _defineProperty(this, 'runQueue', async () => { - if (!this.isActive) { - this.finishQueue(); - return; - } - const nextJob = await this.jobStore.getNextJob(); - if (this.isJobNotEmpty(nextJob)) { - const nextJobs = await this.getJobsForWorker(nextJob.workerName); - const processingJobs = nextJobs.map(async (job) => this.limitExecution(this.excuteJob, job)); - await Promise.all(processingJobs); - } else if (!this.isExecuting()) { - this.finishQueue(); - return; - } - this.scheduleQueue(); - }); - _defineProperty(this, 'limitExecution', async (executer, rawJob) => { - return new Promise(async (resolve) => await this.enqueueJobExecuter(executer, resolve, rawJob)); + } + /** + * @returns true if the Queue is running and false otherwise + */ + get isRunning() { + return this.isActive; + } + /** + * @returns the workers map (readonly) + */ + get registeredWorkers() { + return this.workers; + } + constructor() { + super(); + _defineProperty(this, "emitter", new EventEmitter()); + _defineProperty(this, "jobStore", void 0); + _defineProperty(this, "workers", void 0); + _defineProperty(this, "isActive", void 0); + _defineProperty(this, "timeoutId", void 0); + _defineProperty(this, "executedJobs", void 0); + _defineProperty(this, "activeJobCount", void 0); + _defineProperty(this, "concurrency", void 0); + _defineProperty(this, "updateInterval", void 0); + _defineProperty(this, "onQueueFinish", void 0); + _defineProperty(this, "queuedJobExecuter", []); + _defineProperty(this, "runningJobPromises", void 0); + _defineProperty(this, "resetActiveJob", job => { + this.jobStore.updateJob({ + ...job, + ...{ + active: FALSE + } + }); + }); + _defineProperty(this, "runQueue", async () => { + if (!this.isActive) { + this.finishQueue(); + return; + } + const nextJob = await this.jobStore.getNextJob(); + if (this.isJobNotEmpty(nextJob)) { + const nextJobs = await this.getJobsForWorker(nextJob.workerName); + const processingJobs = nextJobs.map(async job => this.limitExecution(this.excuteJob, job)); + await Promise.all(processingJobs); + } else if (!this.isExecuting()) { + this.finishQueue(); + return; + } + this.scheduleQueue(); + }); + _defineProperty(this, "limitExecution", async (executer, rawJob) => { + return new Promise(async resolve => await this.enqueueJobExecuter(executer, resolve, rawJob)); + }); + _defineProperty(this, "enqueueJobExecuter", async (executer, resolve, rawJob) => { + if (this.isExecuterAvailable()) { + await this.runExecuter(executer, resolve, rawJob); + } else { + this.queuedJobExecuter.push(this.runExecuter.bind(null, executer, resolve, rawJob)); + } + }); + _defineProperty(this, "runExecuter", async (executer, resolve, rawJob) => { + try { + await executer(rawJob); + } finally { + resolve(true); + if (this.queuedJobExecuter.length > 0 && this.isExecuterAvailable()) { + await this.queuedJobExecuter.shift()(); + } + } + }); + _defineProperty(this, "excuteJob", async rawJob => { + const worker = this.workers[rawJob.workerName]; + const payload = JSON.parse(rawJob.payload); + const job = { + ...rawJob, + ...{ + payload + } + }; + try { + job.status = "processing"; + this.jobStore.updateJob({ + ...job, + payload: JSON.stringify(payload) }); - _defineProperty(this, 'enqueueJobExecuter', async (executer, resolve, rawJob) => { - if (this.isExecuterAvailable()) { - await this.runExecuter(executer, resolve, rawJob); - } else { - this.queuedJobExecuter.push(this.runExecuter.bind(null, executer, resolve, rawJob)); - } + this.emit('jobStarted', job); + this.activeJobCount++; + if (!this.workers[rawJob.workerName]) { + throw new QueueError(`Missing worker with name ${rawJob.workerName}`, "error"); + } + const promise = worker.execute(rawJob); + this.runningJobPromises[rawJob.id] = promise; + await promise; + worker.triggerSuccess(job); + job.status = "finished"; + this.jobStore.updateJob({ + ...job, + payload: JSON.stringify(payload) }); - _defineProperty(this, 'runExecuter', async (executer, resolve, rawJob) => { - try { - await executer(rawJob); - } finally { - resolve(true); - if (this.queuedJobExecuter.length > 0 && this.isExecuterAvailable()) { - await this.queuedJobExecuter.shift()(); - } - } + this.jobStore.removeJob(rawJob); + this.emit('jobSucceeded', job); + } catch (err) { + const error = err; + const { + attempts + } = rawJob; + // eslint-disable-next-line prefer-const + let { + errors, + failedAttempts + } = JSON.parse(rawJob.metaData); + failedAttempts++; + let failed = ''; + if (failedAttempts >= attempts) { + failed = new Date().toISOString(); + } + const metaData = JSON.stringify({ + errors: [...errors, error], + failedAttempts }); - _defineProperty(this, 'excuteJob', async (rawJob) => { - const worker = this.workers[rawJob.workerName]; - const payload = JSON.parse(rawJob.payload); - const job = { - ...rawJob, - ...{ - payload, - }, - }; - try { - job.status = 'processing'; - this.jobStore.updateJob({ - ...job, - payload: JSON.stringify(payload), - }); - this.emit('jobStarted', job); - this.activeJobCount++; - if (!this.workers[rawJob.workerName]) { - throw new QueueError(`Missing worker with name ${rawJob.workerName}`, 'error'); - } - const promise = worker.execute(rawJob); - this.runningJobPromises[rawJob.id] = promise; - await promise; - worker.triggerSuccess(job); - job.status = 'finished'; - this.jobStore.updateJob({ - ...job, - payload: JSON.stringify(payload), - }); - this.jobStore.removeJob(rawJob); - this.emit('jobSucceeded', job); - } catch (err) { - const error = err; - const { attempts } = rawJob; - // eslint-disable-next-line prefer-const - let { errors, failedAttempts } = JSON.parse(rawJob.metaData); - failedAttempts++; - let failed = ''; - if (failedAttempts >= attempts) { - failed = new Date().toISOString(); - } - const metaData = JSON.stringify({ - errors: [...errors, error], - failedAttempts, - }); - worker.triggerFailure( - { - ...job, - metaData, - failed, - }, - error - ); - const failedJob = { - ...rawJob, - ...{ - active: FALSE, - metaData, - failed, - status: error.code === 'cancelled' ? 'cancelled' : 'failed', - }, - }; - this.jobStore.updateJob(failedJob); - this.emit('jobFailed', failedJob, error); - } finally { - delete this.runningJobPromises[job.id]; - worker.decreaseExecutionCount(); - worker.triggerCompletion(job); - this.emit('jobCompleted', { - ...job, - }); - this.executedJobs.push(rawJob); - this.activeJobCount--; - } + worker.triggerFailure({ + ...job, + metaData, + failed + }, error); + const failedJob = { + ...rawJob, + ...{ + active: FALSE, + metaData, + failed, + status: error.code === "cancelled" ? "cancelled" : "failed" + } + }; + this.jobStore.updateJob(failedJob); + this.emit('jobFailed', failedJob, error); + } finally { + delete this.runningJobPromises[job.id]; + worker.decreaseExecutionCount(); + worker.triggerCompletion(job); + this.emit('jobCompleted', { + ...job }); - this.jobStore = NativeModules.JobQueue; - this.workers = {}; - this.runningJobPromises = {}; - this.isActive = false; - this.timeoutId = 0; - this.executedJobs = []; - this.activeJobCount = 0; - this.updateInterval = 10; - this.onQueueFinish = (executedJobs) => {}; - this.concurrency = -1; - } + this.executedJobs.push(rawJob); + this.activeJobCount--; + } + }); + this.jobStore = NativeModules.JobQueue; + this.workers = {}; + this.runningJobPromises = {}; + this.isActive = false; + this.timeoutId = 0; + this.executedJobs = []; + this.activeJobCount = 0; + this.updateInterval = 10; + this.onQueueFinish = executedJobs => {}; + this.concurrency = -1; + } - /** - * @returns a promise that resolves all jobs of jobStore - */ - async getJobs() { - return await this.jobStore.getJobs(); - } - async getJobsWithDeleted() { - return await this.jobStore.getJobsWithDeleted(); - } - /** - * @param job the job to be deleted - */ - removeJob(job) { - this.jobStore.removeJob(job); - this.emit('jobDeleted', job); - } - removeJobPermanent(job) { - this.jobStore.removeJobPermanently(job); - this.emit('jobDeleted', job); - } - /** - * @param job the job which should be requeued - */ - requeueJob(job) { - this.jobStore.updateJob({ - ...job, - failed: '', - status: 'idle', - active: TRUE, - }); - if (!this.isActive) { - // eslint-disable-next-line @typescript-eslint/ban-ts-comment - // @ts-ignore - this.start() - .then(() => { - console.log('Queue restarted'); - }) - .catch(() => { - console.log('Queue could not be restarted'); - }); - } + /** + * @returns a promise that resolves all jobs of jobStore + */ + async getJobs() { + return await this.jobStore.getJobs(); + } + async getJobsWithDeleted() { + return await this.jobStore.getJobsWithDeleted(); + } + /** + * @param job the job to be deleted + */ + removeJob(job) { + this.jobStore.removeJob(job); + this.emit("jobDeleted", job); + } + removeJobPermanent(job) { + this.jobStore.removeJobPermanently(job); + this.emit("jobDeleted", job); + } + /** + * @param job the job which should be requeued + */ + requeueJob(job) { + this.jobStore.updateJob({ + ...job, + failed: '', + status: "idle", + active: TRUE + }); + if (!this.isActive) { + // eslint-disable-next-line @typescript-eslint/ban-ts-comment + // @ts-ignore + this.start().then(() => { + console.log("Queue restarted"); + }).catch(() => { + console.log("Queue could not be restarted"); + }); } - configure(options) { - const { onQueueFinish = (executedJobs) => {}, updateInterval = 10, concurrency = -1 } = options; - this.onQueueFinish = onQueueFinish; - this.updateInterval = updateInterval; - this.concurrency = concurrency; - } - /** - * adds a [[Worker]] to the queue which can execute Jobs - * @param worker - */ - addWorker(worker) { - if (this.workers[worker.name]) { - throw new QueueError(`Worker "${worker.name}" already exists.`, 'error'); - } - this.workers[worker.name] = worker; - this.emit('workerAdded', worker.name); + } + configure(options) { + const { + onQueueFinish = executedJobs => {}, + updateInterval = 10, + concurrency = -1 + } = options; + this.onQueueFinish = onQueueFinish; + this.updateInterval = updateInterval; + this.concurrency = concurrency; + } + /** + * adds a [[Worker]] to the queue which can execute Jobs + * @param worker + */ + addWorker(worker) { + if (this.workers[worker.name]) { + throw new QueueError(`Worker "${worker.name}" already exists.`, "error"); } + this.workers[worker.name] = worker; + this.emit('workerAdded', worker.name); + } - /** - * removes worker from queue - * - * @param name - * @param [deleteRelatedJobs=false] removes all queued jobs releated to the worker if set to true - */ - removeWorker(name, deleteRelatedJobs = false) { - delete this.workers[name]; - if (deleteRelatedJobs) { - this.jobStore.removeJobsByWorkerName(name); - } + /** + * removes worker from queue + * + * @param name + * @param [deleteRelatedJobs=false] removes all queued jobs releated to the worker if set to true + */ + removeWorker(name, deleteRelatedJobs = false) { + delete this.workers[name]; + if (deleteRelatedJobs) { + this.jobStore.removeJobsByWorkerName(name); } + } - /** - * adds a job to the queue - * @param workerName name of the worker which should be used to excute the job - * @param [payload={}] payload which is passed as parameter to the executer - * @param [options={ attempts: 0, timeout: 0, priority: 0 }] options to set max attempts, a timeout and a priority - * @param [startQueue=true] if set to false the queue won't start automaticly when adding a job - * @returns job id - */ - addJob( - workerName, - payload, - options = { - attempts: 0, - timeout: 0, - priority: 0, - }, - startQueue = true - ) { - const { attempts = 0, timeout = 0, priority = 0 } = options; - const id = Uuid.v4(); - const job = { - id, - payload: JSON.stringify(payload || {}), - metaData: JSON.stringify({ - failedAttempts: 0, - errors: [], - }), - active: FALSE, - created: new Date().toISOString(), - failed: '', - workerName, - attempts, - timeout, - priority, - isDeleted: false, - status: 'idle', - }; - if (!this.workers[job.workerName]) { - throw new QueueError(`Missing worker with name ${job.workerName}`); - } - this.jobStore.addJob(job); - this.emit('jobAdded', job); - if (startQueue && !this.isActive) { - this.start(); - } - return id; + /** + * adds a job to the queue + * @param workerName name of the worker which should be used to excute the job + * @param [payload={}] payload which is passed as parameter to the executer + * @param [options={ attempts: 0, timeout: 0, priority: 0 }] options to set max attempts, a timeout and a priority + * @param [startQueue=true] if set to false the queue won't start automaticly when adding a job + * @returns job id + */ + addJob(workerName, payload, options = { + attempts: 0, + timeout: 0, + priority: 0 + }, startQueue = true) { + const { + attempts = 0, + timeout = 0, + priority = 0 + } = options; + const id = Uuid.v4(); + const job = { + id, + payload: JSON.stringify(payload || {}), + metaData: JSON.stringify({ + failedAttempts: 0, + errors: [] + }), + active: FALSE, + created: new Date().toISOString(), + failed: '', + workerName, + attempts, + timeout, + priority, + isDeleted: false, + status: "idle" + }; + if (!this.workers[job.workerName]) { + throw new QueueError(`Missing worker with name ${job.workerName}`); } - /** - * starts the queue to execute queued jobs - */ - async start() { - if (!this.isActive) { - this.isActive = true; - this.executedJobs = []; - await this.resetActiveJobs(); - this.scheduleQueue(); - } + this.jobStore.addJob(job); + this.emit('jobAdded', job); + if (startQueue && !this.isActive) { + this.start(); } - /** - * stop the queue from executing queued jobs - */ - stop() { - this.isActive = false; + return id; + } + /** + * starts the queue to execute queued jobs + */ + async start() { + if (!this.isActive) { + this.isActive = true; + this.executedJobs = []; + await this.resetActiveJobs(); + this.scheduleQueue(); } + } + /** + * stop the queue from executing queued jobs + */ + stop() { + this.isActive = false; + } - /** - * cancel running job - */ - cancelJob(jobId, exception) { - const promise = this.runningJobPromises[jobId]; - if (promise !== undefined && typeof promise[CANCEL] === 'function') { - promise[CANCEL](exception || new QueueError(`job canceled`, 'cancelled')); - } else if (!promise[CANCEL]) { - console.warn('Worker does not have a cancel method implemented'); - } else { - throw new QueueError(`Job with id ${jobId} not currently running`, 'error'); - } + /** + * cancel running job + */ + cancelJob(jobId, exception) { + const promise = this.runningJobPromises[jobId]; + if (promise !== undefined && typeof promise[CANCEL] === 'function') { + promise[CANCEL](exception || new QueueError(`job canceled`, "cancelled")); + } else if (!promise[CANCEL]) { + console.warn('Worker does not have a cancel method implemented'); + } else { + throw new QueueError(`Job with id ${jobId} not currently running`, "error"); } - async cancelAllActiveJobs() { - const jobs = await this.jobStore.getActiveMarkedJobs(); - jobs.forEach((job) => { - const newJob = { - ...job, - ...{ - active: FALSE, - status: 'cancelled', - }, - }; - const isRunning = this.runningJobPromises[job.id]; - // eslint-disable-next-line @typescript-eslint/no-misused-promises - if (!!Boolean(isRunning)) { - this.cancelJob(job.id, new QueueError(`Job with id ${job.id} cancelled`, 'cancelled')); - } - this.jobStore.updateJob(newJob); - this.emit('jobCancelled', newJob); - }); - } - cancelActiveJob(job) { - const newJob = { - ...job, - ...{ - active: FALSE, - status: 'cancelled', - }, - }; - const isRunning = this.runningJobPromises[job.id]; - // eslint-disable-next-line @typescript-eslint/no-misused-promises - if (!!isRunning) { - this.cancelJob(job.id, new QueueError(`Job with id ${job.id} cancelled`, 'cancelled')); - } - this.jobStore.updateJob(newJob); - this.emit('jobCancelled', newJob); - } - async resetActiveJobs() { - const activeMarkedJobs = await this.jobStore.getActiveMarkedJobs(); - const resetTasks = activeMarkedJobs.map(this.resetActiveJob); - await Promise.all(resetTasks); - } - scheduleQueue() { - if (AppState.currentState === 'active' && Platform.OS === 'ios') { - this.timeoutId = setTimeout(this.runQueue, this.updateInterval); - } else { - this.runQueue(); + } + async cancelAllActiveJobs() { + const jobs = await this.jobStore.getActiveMarkedJobs(); + jobs.forEach(job => { + const newJob = { + ...job, + ...{ + active: FALSE, + status: "cancelled" } + }; + const isRunning = this.runningJobPromises[job.id]; + // eslint-disable-next-line @typescript-eslint/no-misused-promises + if (!!Boolean(isRunning)) { + this.cancelJob(job.id, new QueueError(`Job with id ${job.id} cancelled`, "cancelled")); + } + this.jobStore.updateJob(newJob); + this.emit('jobCancelled', newJob); + }); + } + cancelActiveJob(job) { + const newJob = { + ...job, + ...{ + active: FALSE, + status: "cancelled" + } + }; + const isRunning = this.runningJobPromises[job.id]; + // eslint-disable-next-line @typescript-eslint/no-misused-promises + if (!!isRunning) { + this.cancelJob(job.id, new QueueError(`Job with id ${job.id} cancelled`, "cancelled")); } - isJobNotEmpty(rawJob) { - return Object.keys(rawJob).length > 0; + this.jobStore.updateJob(newJob); + this.emit('jobCancelled', newJob); + } + async resetActiveJobs() { + const activeMarkedJobs = await this.jobStore.getActiveMarkedJobs(); + const resetTasks = activeMarkedJobs.map(this.resetActiveJob); + await Promise.all(resetTasks); + } + scheduleQueue() { + if (AppState.currentState === 'active' && Platform.OS === "ios") { + this.timeoutId = setTimeout(this.runQueue, this.updateInterval); + } else { + this.runQueue(); } - isExecuterAvailable() { - return this.concurrency <= 0 || this.activeJobCount < this.concurrency; + } + isJobNotEmpty(rawJob) { + return Object.keys(rawJob).length > 0; + } + isExecuterAvailable() { + return this.concurrency <= 0 || this.activeJobCount < this.concurrency; + } + isExecuting() { + return this.activeJobCount > 0; + } + finishQueue() { + this.onQueueFinish(this.executedJobs); + this.isActive = false; + clearTimeout(this.timeoutId); + } + async getJobsForWorker(workerName) { + const { + isBusy, + availableExecuters + } = this.workers[workerName]; + if (!isBusy) { + return await this.jobStore.getJobsForWorker(workerName, availableExecuters); + } else { + return await this.getJobsForAlternateWorker(); } - isExecuting() { - return this.activeJobCount > 0; + } + async getJobsForWorkerWithDeleted(workerName) { + const { + isBusy, + availableExecuters + } = this.workers[workerName]; + if (!isBusy) { + return await this.jobStore.getJobsForWorkerWithDeleted(workerName, availableExecuters); + } else { + return await this.getJobsForAlternateWorker(); } - finishQueue() { - this.onQueueFinish(this.executedJobs); - this.isActive = false; - clearTimeout(this.timeoutId); - } - async getJobsForWorker(workerName) { - const { isBusy, availableExecuters } = this.workers[workerName]; - if (!isBusy) { - return await this.jobStore.getJobsForWorker(workerName, availableExecuters); - } else { - return await this.getJobsForAlternateWorker(); - } - } - async getJobsForWorkerWithDeleted(workerName) { - const { isBusy, availableExecuters } = this.workers[workerName]; - if (!isBusy) { - return await this.jobStore.getJobsForWorkerWithDeleted(workerName, availableExecuters); - } else { - return await this.getJobsForAlternateWorker(); - } - } - async getJobsForAlternateWorker() { - for (const workerName of Object.keys(this.workers)) { - const { isBusy, availableExecuters } = this.workers[workerName]; - let nextJobs = []; - if (!isBusy) { - nextJobs = await this.jobStore.getJobsForWorker(workerName, availableExecuters); - } - if (nextJobs.length > 0) { - return nextJobs; - } - } - return []; + } + async getJobsForAlternateWorker() { + for (const workerName of Object.keys(this.workers)) { + const { + isBusy, + availableExecuters + } = this.workers[workerName]; + let nextJobs = []; + if (!isBusy) { + nextJobs = await this.jobStore.getJobsForWorker(workerName, availableExecuters); + } + if (nextJobs.length > 0) { + return nextJobs; + } } + return []; + } } _Queue = Queue; -_defineProperty(Queue, 'queueInstance', void 0); +_defineProperty(Queue, "queueInstance", void 0); export default Queue.instance; -//# sourceMappingURL=Queue.js.map +//# sourceMappingURL=Queue.js.map \ No newline at end of file diff --git a/lib/module/Queue.js.map b/lib/module/Queue.js.map index 8ce60af..2d408e0 100644 --- a/lib/module/Queue.js.map +++ b/lib/module/Queue.js.map @@ -1,150 +1 @@ -{ - "version": 3, - "names": [ - "AppState", - "NativeModules", - "Platform", - "FALSE", - "TRUE", - "Uuid", - "CANCEL", - "EventEmitter", - "QueueError", - "Error", - "constructor", - "message", - "code", - "_defineProperty", - "name", - "Queue", - "instance", - "queueInstance", - "isRunning", - "isActive", - "registeredWorkers", - "workers", - "job", - "jobStore", - "updateJob", - "active", - "finishQueue", - "nextJob", - "getNextJob", - "isJobNotEmpty", - "nextJobs", - "getJobsForWorker", - "workerName", - "processingJobs", - "map", - "limitExecution", - "excuteJob", - "Promise", - "all", - "isExecuting", - "scheduleQueue", - "executer", - "rawJob", - "resolve", - "enqueueJobExecuter", - "isExecuterAvailable", - "runExecuter", - "queuedJobExecuter", - "push", - "bind", - "length", - "shift", - "worker", - "payload", - "JSON", - "parse", - "status", - "stringify", - "emit", - "activeJobCount", - "promise", - "execute", - "runningJobPromises", - "id", - "triggerSuccess", - "removeJob", - "err", - "error", - "attempts", - "errors", - "failedAttempts", - "metaData", - "failed", - "Date", - "toISOString", - "triggerFailure", - "failedJob", - "decreaseExecutionCount", - "triggerCompletion", - "executedJobs", - "JobQueue", - "timeoutId", - "updateInterval", - "onQueueFinish", - "concurrency", - "getJobs", - "getJobsWithDeleted", - "removeJobPermanent", - "removeJobPermanently", - "requeueJob", - "start", - "then", - "console", - "log", - "catch", - "configure", - "options", - "addWorker", - "removeWorker", - "deleteRelatedJobs", - "removeJobsByWorkerName", - "addJob", - "timeout", - "priority", - "startQueue", - "v4", - "created", - "isDeleted", - "resetActiveJobs", - "stop", - "cancelJob", - "jobId", - "exception", - "undefined", - "warn", - "cancelAllActiveJobs", - "jobs", - "getActiveMarkedJobs", - "forEach", - "newJob", - "Boolean", - "cancelActiveJob", - "activeMarkedJobs", - "resetTasks", - "resetActiveJob", - "currentState", - "OS", - "setTimeout", - "runQueue", - "Object", - "keys", - "clearTimeout", - "isBusy", - "availableExecuters", - "getJobsForAlternateWorker", - "getJobsForWorkerWithDeleted", - "_Queue" - ], - "sources": [ - "Queue.ts" - ], - "sourcesContent": [ - "/* eslint-disable no-extra-boolean-cast */\n/* eslint-disable @typescript-eslint/no-empty-function */\nimport { AppState, NativeModules, Platform } from 'react-native';\n\nimport { FALSE, Job, RawJob, TRUE } from './models/Job';\nimport { JobStore } from './models/JobStore';\nimport { Uuid } from './utils/Uuid';\nimport { Worker, CANCEL, CancellablePromise } from './Worker';\n\n\nimport EventEmitter from 'eventemitter3';\n\ntype QueueErrorType = \"cancelled\" | \"error\";\n\nexport class QueueError extends Error {\n code: QueueErrorType;\n constructor(message: string, code: QueueErrorType = \"error\") {\n super(message);\n this.name = 'QueueError';\n this.code = code;\n }\n}\n\n/**\n * Events emitted by the Queue.\n */\nexport interface QueueEvents {\n /**\n * Fired when a worker is added.\n * @param workerName Name of the worker.\n */\n workerAdded: (workerName: string) => void;\n\n /**\n * Fired when a job is added to the queue.\n * @param job The RawJob that was added.\n */\n jobAdded: (job: RawJob) => void;\n\n /**\n * Fired when a job starts processing.\n * @param job The RawJob that started.\n */\n jobStarted: (job: RawJob) => void;\n\n /**\n * Fired when a job completes successfully.\n * @param job The Job with payload that succeeded.\n */\n jobSucceeded: (job: Job) => void;\n\n /**\n * Fired when a job fails.\n * @param job The RawJob that failed.\n * @param error The error thrown.\n */\n jobFailed: (job: RawJob, error: Error) => void;\n\n /**\n * Fired when a job fails.\n * @param job The RawJob that failed.\n * @param error The error thrown.\n */\n jobCancelled: (job: RawJob) => void;\n\n /**\n * Fired when a job completes (regardless of success or failure).\n * @param job The RawJob that finished.\n */\n jobCompleted: (job: RawJob) => void;\n\n jobDeleted: (job: RawJob) => void\n}\n\n\n/**\n * Options to configure the queue\n */\nexport interface QueueOptions {\n /**\n * A callback function which is called after the queue has been stopped\n * @parameter executedJobs\n */\n onQueueFinish?: (executedJobs: Array>) => void;\n /**\n * Interval in which the queue checks for new jobs to execute\n */\n updateInterval?: number;\n concurrency?: number;\n}\n/**\n * ## Usage\n *\n * ```typescript\n * import queue from 'react-native-job-queue'\n *\n * queue.configure({onQueueFinish:(executedJobs:Job[])=>{\n * console.log(\"Queue stopped and executed\",executedJobs)\n * }});\n * queue.addWorker(new Worker(\"testWorker\",async(payload, id)=>{\n * return new Promise((resolve) => {\n * setTimeout(() => {\n * console.log('Executing jobId', id, 'with:', payload.text);\n * resolve();\n * }, payload.delay);});\n * }))\n * queue.addJob(\"testWorker\",{text:\"Job example payload content text\",delay:5000})\n * ```\n */\nexport class Queue extends EventEmitter {\n static get instance() {\n if (this.queueInstance) {\n return this.queueInstance;\n } else {\n this.queueInstance = new Queue();\n return this.queueInstance;\n }\n }\n /**\n * @returns true if the Queue is running and false otherwise\n */\n get isRunning() {\n return this.isActive;\n }\n /**\n * @returns the workers map (readonly)\n */\n get registeredWorkers() {\n return this.workers;\n }\n private static queueInstance: Queue | null;\n private emitter: EventEmitter = new EventEmitter();\n\n private jobStore: JobStore;\n private workers: { [key: string]: Worker };\n private isActive: boolean;\n\n private timeoutId: number;\n private executedJobs: Array>;\n private activeJobCount: number;\n\n private concurrency: number;\n private updateInterval: number;\n private onQueueFinish: (executedJobs: Array>) => void;\n\n private queuedJobExecuter: any[] = [];\n private runningJobPromises: { [key: string]: CancellablePromise };\n\n private constructor() {\n super();\n this.jobStore = NativeModules.JobQueue;\n this.workers = {};\n this.runningJobPromises = {};\n this.isActive = false;\n\n this.timeoutId = 0;\n this.executedJobs = [];\n this.activeJobCount = 0;\n\n this.updateInterval = 10;\n this.onQueueFinish = (executedJobs: Array>) => { };\n this.concurrency = -1;\n }\n\n\n\n /**\n * @returns a promise that resolves all jobs of jobStore\n */\n async getJobs() {\n return await this.jobStore.getJobs();\n }\n async getJobsWithDeleted() {\n return await this.jobStore.getJobsWithDeleted();\n }\n /**\n * @param job the job to be deleted\n */\n removeJob(job: RawJob) {\n this.jobStore.removeJob(job);\n this.emit(\"jobDeleted\", job)\n }\n removeJobPermanent(job: RawJob) {\n this.jobStore.removeJobPermanently(job);\n this.emit(\"jobDeleted\", job)\n }\n /**\n * @param job the job which should be requeued\n */\n requeueJob(job: RawJob) {\n this.jobStore.updateJob({ ...job, failed: '', status: \"idle\", active: TRUE });\n\n if (!this.isActive) {\n // eslint-disable-next-line @typescript-eslint/ban-ts-comment\n // @ts-ignore\n this.start().then(() => {\n console.log(\"Queue restarted\")\n }).catch(() => {\n console.log(\"Queue could not be restarted\")\n });\n }\n }\n\n configure(options: QueueOptions) {\n const {\n onQueueFinish = (executedJobs: Array>) => { },\n updateInterval = 10,\n concurrency = -1,\n } = options;\n this.onQueueFinish = onQueueFinish;\n this.updateInterval = updateInterval;\n this.concurrency = concurrency;\n }\n /**\n * adds a [[Worker]] to the queue which can execute Jobs\n * @param worker\n */\n addWorker(worker: Worker) {\n if (this.workers[worker.name]) {\n throw new QueueError(`Worker \"${worker.name}\" already exists.`, \"error\");\n }\n this.workers[worker.name] = worker;\n this.emit('workerAdded', worker.name);\n }\n\n /**\n * removes worker from queue\n *\n * @param name\n * @param [deleteRelatedJobs=false] removes all queued jobs releated to the worker if set to true\n */\n removeWorker(name: string, deleteRelatedJobs = false) {\n delete this.workers[name];\n if (deleteRelatedJobs) {\n this.jobStore.removeJobsByWorkerName(name);\n }\n }\n\n /**\n * adds a job to the queue\n * @param workerName name of the worker which should be used to excute the job\n * @param [payload={}] payload which is passed as parameter to the executer\n * @param [options={ attempts: 0, timeout: 0, priority: 0 }] options to set max attempts, a timeout and a priority\n * @param [startQueue=true] if set to false the queue won't start automaticly when adding a job\n * @returns job id\n */\n addJob

(\n workerName: string,\n payload: P,\n options = { attempts: 0, timeout: 0, priority: 0 },\n startQueue = true\n ) {\n const { attempts = 0, timeout = 0, priority = 0 } = options;\n const id: string = Uuid.v4();\n const job: RawJob = {\n id,\n payload: JSON.stringify(payload || {}),\n metaData: JSON.stringify({ failedAttempts: 0, errors: [] }),\n active: FALSE,\n created: new Date().toISOString(),\n failed: '',\n workerName,\n attempts,\n timeout,\n priority,\n isDeleted: false,\n status: \"idle\"\n };\n if (!this.workers[job.workerName]) {\n throw new QueueError(`Missing worker with name ${job.workerName}`);\n }\n\n this.jobStore.addJob(job);\n this.emit('jobAdded', job);\n if (startQueue && !this.isActive) {\n this.start();\n }\n\n return id;\n }\n /**\n * starts the queue to execute queued jobs\n */\n async start() {\n if (!this.isActive) {\n this.isActive = true;\n this.executedJobs = [];\n await this.resetActiveJobs();\n this.scheduleQueue();\n }\n }\n /**\n * stop the queue from executing queued jobs\n */\n stop() {\n this.isActive = false;\n }\n\n /**\n * cancel running job\n */\n cancelJob(jobId: string, exception?: Error) {\n const promise = this.runningJobPromises[jobId];\n if (promise !== undefined && typeof promise[CANCEL] === 'function') {\n promise[CANCEL](exception || new QueueError(`job canceled`, \"cancelled\"));\n } else if (!promise[CANCEL]) {\n console.warn('Worker does not have a cancel method implemented');\n } else {\n throw new QueueError(`Job with id ${jobId} not currently running`, \"error\");\n }\n }\n async cancelAllActiveJobs() {\n const jobs = await this.jobStore.getActiveMarkedJobs()\n\n jobs.forEach((job) => {\n const newJob = { ...job, ...{ active: FALSE, status: \"cancelled\" } };\n const isRunning = this.runningJobPromises[job.id];\n // eslint-disable-next-line @typescript-eslint/no-misused-promises\n if (!!Boolean(isRunning)) {\n this.cancelJob(job.id, new QueueError(`Job with id ${job.id} cancelled`, \"cancelled\"));\n }\n this.jobStore.updateJob(newJob as RawJob);\n this.emit('jobCancelled', newJob as RawJob);\n })\n }\n cancelActiveJob(job: RawJob) {\n const newJob = { ...job, ...{ active: FALSE, status: \"cancelled\" } };\n\n const isRunning = this.runningJobPromises[job.id];\n // eslint-disable-next-line @typescript-eslint/no-misused-promises\n if (!!isRunning) {\n this.cancelJob(job.id, new QueueError(`Job with id ${job.id} cancelled`, \"cancelled\"));\n }\n\n this.jobStore.updateJob(newJob as RawJob);\n\n this.emit('jobCancelled', newJob as RawJob);\n }\n\n private resetActiveJob = (job: RawJob) => {\n this.jobStore.updateJob({ ...job, ...{ active: FALSE } });\n };\n private async resetActiveJobs() {\n const activeMarkedJobs = await this.jobStore.getActiveMarkedJobs();\n const resetTasks = activeMarkedJobs.map(this.resetActiveJob);\n await Promise.all(resetTasks);\n }\n private scheduleQueue() {\n if (AppState.currentState === 'active' && Platform.OS === \"ios\") {\n this.timeoutId = setTimeout(this.runQueue, this.updateInterval);\n } else {\n this.runQueue();\n }\n }\n private runQueue = async () => {\n if (!this.isActive) {\n this.finishQueue();\n return;\n }\n const nextJob = await this.jobStore.getNextJob();\n if (this.isJobNotEmpty(nextJob)) {\n const nextJobs = await this.getJobsForWorker(nextJob.workerName);\n const processingJobs = nextJobs.map(async (job) => this.limitExecution(this.excuteJob, job));\n await Promise.all(processingJobs);\n } else if (!this.isExecuting()) {\n this.finishQueue();\n return;\n }\n this.scheduleQueue();\n };\n\n private isJobNotEmpty(rawJob: RawJob | {}) {\n return Object.keys(rawJob).length > 0;\n }\n\n private limitExecution = async (executer: (rawJob: RawJob) => Promise, rawJob: RawJob) => {\n return new Promise(async (resolve) => await this.enqueueJobExecuter(executer, resolve, rawJob));\n };\n\n private enqueueJobExecuter = async (\n executer: (rawJob: RawJob) => Promise,\n resolve: (_: unknown) => void,\n rawJob: RawJob\n ) => {\n if (this.isExecuterAvailable()) {\n await this.runExecuter(executer, resolve, rawJob);\n } else {\n this.queuedJobExecuter.push(this.runExecuter.bind(null, executer, resolve, rawJob));\n }\n };\n\n private runExecuter = async (\n executer: (rawJob: RawJob) => Promise,\n resolve: (_: unknown) => void,\n rawJob: RawJob\n ) => {\n try {\n await executer(rawJob);\n } finally {\n resolve(true);\n if (this.queuedJobExecuter.length > 0 && this.isExecuterAvailable()) {\n await this.queuedJobExecuter.shift()();\n }\n }\n };\n private isExecuterAvailable() {\n return this.concurrency <= 0 || this.activeJobCount < this.concurrency;\n }\n private isExecuting() {\n return this.activeJobCount > 0;\n }\n\n private finishQueue() {\n this.onQueueFinish(this.executedJobs);\n this.isActive = false;\n clearTimeout(this.timeoutId);\n }\n\n async getJobsForWorker(workerName: string) {\n const { isBusy, availableExecuters } = this.workers[workerName];\n if (!isBusy) {\n return await this.jobStore.getJobsForWorker(workerName, availableExecuters);\n } else {\n return await this.getJobsForAlternateWorker();\n }\n }\n\n async getJobsForWorkerWithDeleted(workerName: string) {\n const { isBusy, availableExecuters } = this.workers[workerName];\n if (!isBusy) {\n return await this.jobStore.getJobsForWorkerWithDeleted(workerName, availableExecuters);\n } else {\n return await this.getJobsForAlternateWorker();\n }\n }\n\n private async getJobsForAlternateWorker() {\n for (const workerName of Object.keys(this.workers)) {\n const { isBusy, availableExecuters } = this.workers[workerName];\n let nextJobs: RawJob[] = [];\n if (!isBusy) {\n nextJobs = await this.jobStore.getJobsForWorker(workerName, availableExecuters);\n }\n if (nextJobs.length > 0) {\n return nextJobs;\n }\n }\n return [];\n }\n\n private excuteJob = async (rawJob: RawJob) => {\n const worker = this.workers[rawJob.workerName];\n const payload = JSON.parse(rawJob.payload) as Worker;\n const job = { ...rawJob, ...{ payload } } as Job;\n\n try {\n job.status = \"processing\";\n this.jobStore.updateJob({ ...job, payload: JSON.stringify(payload) });\n this.emit('jobStarted', job);\n\n this.activeJobCount++;\n if (!this.workers[rawJob.workerName]) {\n throw new QueueError(`Missing worker with name ${rawJob.workerName}`, \"error\");\n }\n const promise = worker.execute(rawJob);\n\n this.runningJobPromises[rawJob.id] = promise;\n await promise;\n\n worker.triggerSuccess(job);\n job.status = \"finished\";\n this.jobStore.updateJob({ ...job, payload: JSON.stringify(payload) });\n this.jobStore.removeJob(rawJob);\n this.emit('jobSucceeded', job);\n } catch (err) {\n const error = err as QueueError;\n const { attempts } = rawJob;\n // eslint-disable-next-line prefer-const\n let { errors, failedAttempts } = JSON.parse(rawJob.metaData) as { errors: string[]; failedAttempts: number };\n failedAttempts++;\n let failed = '';\n if (failedAttempts >= attempts) {\n failed = new Date().toISOString();\n }\n const metaData = JSON.stringify({ errors: [...errors, error], failedAttempts });\n worker.triggerFailure({ ...job, metaData, failed }, error);\n const failedJob = { ...rawJob, ...{ active: FALSE, metaData, failed, status: error.code === \"cancelled\" ? \"cancelled\" : \"failed\" } } as RawJob;\n this.jobStore.updateJob(failedJob);\n this.emit('jobFailed', failedJob, error);\n } finally {\n delete this.runningJobPromises[job.id];\n worker.decreaseExecutionCount();\n worker.triggerCompletion(job);\n this.emit('jobCompleted', { ...job });\n this.executedJobs.push(rawJob);\n this.activeJobCount--;\n }\n };\n}\nexport default Queue.instance;\n" - ], - "mappings": ";;;;AAAA;AACA;AACA,SAASA,QAAQ,EAAEC,aAAa,EAAEC,QAAQ,QAAQ,cAAc;AAEhE,SAASC,KAAK,EAAeC,IAAI,QAAQ,cAAc;AAEvD,SAASC,IAAI,QAAQ,cAAc;AACnC,SAAiBC,MAAM,QAA4B,UAAU;AAG7D,OAAOC,YAAY,MAAM,eAAe;AAIxC,OAAO,MAAMC,UAAU,SAASC,KAAK,CAAC;EAElCC,WAAWA,CAACC,OAAe,EAAEC,IAAoB,GAAG,OAAO,EAAE;IACzD,KAAK,CAACD,OAAO,CAAC;IAACE,eAAA;IACf,IAAI,CAACC,IAAI,GAAG,YAAY;IACxB,IAAI,CAACF,IAAI,GAAGA,IAAI;EACpB;AACJ;;AAEA;AACA;AACA;;AAkDA;AACA;AACA;;AAaA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,MAAMG,KAAK,SAASR,YAAY,CAAc;EACjD,WAAWS,QAAQA,CAAA,EAAG;IAClB,IAAI,IAAI,CAACC,aAAa,EAAE;MACpB,OAAO,IAAI,CAACA,aAAa;IAC7B,CAAC,MAAM;MACH,IAAI,CAACA,aAAa,GAAG,IAAIF,KAAK,CAAC,CAAC;MAChC,OAAO,IAAI,CAACE,aAAa;IAC7B;EACJ;EACA;AACJ;AACA;EACI,IAAIC,SAASA,CAAA,EAAG;IACZ,OAAO,IAAI,CAACC,QAAQ;EACxB;EACA;AACJ;AACA;EACI,IAAIC,iBAAiBA,CAAA,EAAG;IACpB,OAAO,IAAI,CAACC,OAAO;EACvB;EAmBQX,WAAWA,CAAA,EAAG;IAClB,KAAK,CAAC,CAAC;IAACG,eAAA,kBAlBiC,IAAIN,YAAY,CAAc,CAAC;IAAAM,eAAA;IAAAA,eAAA;IAA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AAM,IAAI,CAACP,QAAQ,CAACQ,gBAAgB,CAACC,UAAU,EAAEqG,kBAAkB,CAAC;MACnF;MACA,IAAIvG,QAAQ,CAACoB,MAAM,GAAG,CAAC,EAAE;QACrB,OAAOpB,QAAQ;MACnB;IACJ;IACA,OAAO,EAAE;EACb;AAkDJ;AAAC0G,MAAA,GArYYzH,KAAK;AAAAF,eAAA,CAALE,KAAK;AAsYlB,eAAeA,KAAK,CAACC,QAAQ", - "ignoreList": [] -} \ No newline at end of file +{"version":3,"names":["AppState","NativeModules","Platform","FALSE","TRUE","Uuid","CANCEL","EventEmitter","QueueError","Error","constructor","message","code","_defineProperty","name","Queue","instance","queueInstance","isRunning","isActive","registeredWorkers","workers","job","jobStore","updateJob","active","finishQueue","nextJob","getNextJob","isJobNotEmpty","nextJobs","getJobsForWorker","workerName","processingJobs","map","limitExecution","excuteJob","Promise","all","isExecuting","scheduleQueue","executer","rawJob","resolve","enqueueJobExecuter","isExecuterAvailable","runExecuter","queuedJobExecuter","push","bind","length","shift","worker","payload","JSON","parse","status","stringify","emit","activeJobCount","promise","execute","runningJobPromises","id","triggerSuccess","removeJob","err","error","attempts","errors","failedAttempts","metaData","failed","Date","toISOString","triggerFailure","failedJob","decreaseExecutionCount","triggerCompletion","executedJobs","JobQueue","timeoutId","updateInterval","onQueueFinish","concurrency","getJobs","getJobsWithDeleted","removeJobPermanent","removeJobPermanently","requeueJob","start","then","console","log","catch","configure","options","addWorker","removeWorker","deleteRelatedJobs","removeJobsByWorkerName","addJob","timeout","priority","startQueue","v4","created","isDeleted","resetActiveJobs","stop","cancelJob","jobId","exception","undefined","warn","cancelAllActiveJobs","jobs","getActiveMarkedJobs","forEach","newJob","Boolean","cancelActiveJob","activeMarkedJobs","resetTasks","resetActiveJob","currentState","OS","setTimeout","runQueue","Object","keys","clearTimeout","isBusy","availableExecuters","getJobsForAlternateWorker","getJobsForWorkerWithDeleted","_Queue"],"sources":["Queue.ts"],"sourcesContent":["/* eslint-disable no-extra-boolean-cast */\n/* eslint-disable @typescript-eslint/no-empty-function */\nimport { AppState, NativeModules, Platform } from 'react-native';\n\nimport { FALSE, Job, RawJob, TRUE } from './models/Job';\nimport { JobStore } from './models/JobStore';\nimport { Uuid } from './utils/Uuid';\nimport { Worker, CANCEL, CancellablePromise } from './Worker';\n\n\nimport EventEmitter from 'eventemitter3';\n\ntype QueueErrorType = \"cancelled\" | \"error\";\n\nexport class QueueError extends Error {\n code: QueueErrorType;\n constructor(message: string, code: QueueErrorType = \"error\") {\n super(message);\n this.name = 'QueueError';\n this.code = code;\n }\n}\n\n/**\n * Events emitted by the Queue.\n */\nexport interface QueueEvents {\n /**\n * Fired when a worker is added.\n * @param workerName Name of the worker.\n */\n workerAdded: (workerName: string) => void;\n\n /**\n * Fired when a job is added to the queue.\n * @param job The RawJob that was added.\n */\n jobAdded: (job: RawJob) => void;\n\n /**\n * Fired when a job starts processing.\n * @param job The RawJob that started.\n */\n jobStarted: (job: RawJob) => void;\n\n /**\n * Fired when a job completes successfully.\n * @param job The Job with payload that succeeded.\n */\n jobSucceeded: (job: Job) => void;\n\n /**\n * Fired when a job fails.\n * @param job The RawJob that failed.\n * @param error The error thrown.\n */\n jobFailed: (job: RawJob, error: Error) => void;\n\n /**\n * Fired when a job fails.\n * @param job The RawJob that failed.\n * @param error The error thrown.\n */\n jobCancelled: (job: RawJob) => void;\n\n /**\n * Fired when a job completes (regardless of success or failure).\n * @param job The RawJob that finished.\n */\n jobCompleted: (job: RawJob) => void;\n\n jobDeleted: (job: RawJob) => void\n}\n\n\n/**\n * Options to configure the queue\n */\nexport interface QueueOptions {\n /**\n * A callback function which is called after the queue has been stopped\n * @parameter executedJobs\n */\n onQueueFinish?: (executedJobs: Array>) => void;\n /**\n * Interval in which the queue checks for new jobs to execute\n */\n updateInterval?: number;\n concurrency?: number;\n}\n/**\n * ## Usage\n *\n * ```typescript\n * import queue from 'react-native-job-queue'\n *\n * queue.configure({onQueueFinish:(executedJobs:Job[])=>{\n * console.log(\"Queue stopped and executed\",executedJobs)\n * }});\n * queue.addWorker(new Worker(\"testWorker\",async(payload, id)=>{\n * return new Promise((resolve) => {\n * setTimeout(() => {\n * console.log('Executing jobId', id, 'with:', payload.text);\n * resolve();\n * }, payload.delay);});\n * }))\n * queue.addJob(\"testWorker\",{text:\"Job example payload content text\",delay:5000})\n * ```\n */\nexport class Queue extends EventEmitter {\n static get instance() {\n if (this.queueInstance) {\n return this.queueInstance;\n } else {\n this.queueInstance = new Queue();\n return this.queueInstance;\n }\n }\n /**\n * @returns true if the Queue is running and false otherwise\n */\n get isRunning() {\n return this.isActive;\n }\n /**\n * @returns the workers map (readonly)\n */\n get registeredWorkers() {\n return this.workers;\n }\n private static queueInstance: Queue | null;\n private emitter: EventEmitter = new EventEmitter();\n\n private jobStore: JobStore;\n private workers: { [key: string]: Worker };\n private isActive: boolean;\n\n private timeoutId: number;\n private executedJobs: Array>;\n private activeJobCount: number;\n\n private concurrency: number;\n private updateInterval: number;\n private onQueueFinish: (executedJobs: Array>) => void;\n\n private queuedJobExecuter: any[] = [];\n private runningJobPromises: { [key: string]: CancellablePromise };\n\n private constructor() {\n super();\n this.jobStore = NativeModules.JobQueue;\n this.workers = {};\n this.runningJobPromises = {};\n this.isActive = false;\n\n this.timeoutId = 0;\n this.executedJobs = [];\n this.activeJobCount = 0;\n\n this.updateInterval = 10;\n this.onQueueFinish = (executedJobs: Array>) => { };\n this.concurrency = -1;\n }\n\n\n\n /**\n * @returns a promise that resolves all jobs of jobStore\n */\n async getJobs() {\n return await this.jobStore.getJobs();\n }\n async getJobsWithDeleted() {\n return await this.jobStore.getJobsWithDeleted();\n }\n /**\n * @param job the job to be deleted\n */\n removeJob(job: RawJob) {\n this.jobStore.removeJob(job);\n this.emit(\"jobDeleted\", job)\n }\n removeJobPermanent(job: RawJob) {\n this.jobStore.removeJobPermanently(job);\n this.emit(\"jobDeleted\", job)\n }\n /**\n * @param job the job which should be requeued\n */\n requeueJob(job: RawJob) {\n this.jobStore.updateJob({ ...job, failed: '', status: \"idle\", active: TRUE });\n\n if (!this.isActive) {\n // eslint-disable-next-line @typescript-eslint/ban-ts-comment\n // @ts-ignore\n this.start().then(() => {\n console.log(\"Queue restarted\")\n }).catch(() => {\n console.log(\"Queue could not be restarted\")\n });\n }\n }\n\n configure(options: QueueOptions) {\n const {\n onQueueFinish = (executedJobs: Array>) => { },\n updateInterval = 10,\n concurrency = -1,\n } = options;\n this.onQueueFinish = onQueueFinish;\n this.updateInterval = updateInterval;\n this.concurrency = concurrency;\n }\n /**\n * adds a [[Worker]] to the queue which can execute Jobs\n * @param worker\n */\n addWorker(worker: Worker) {\n if (this.workers[worker.name]) {\n throw new QueueError(`Worker \"${worker.name}\" already exists.`, \"error\");\n }\n this.workers[worker.name] = worker;\n this.emit('workerAdded', worker.name);\n }\n\n /**\n * removes worker from queue\n *\n * @param name\n * @param [deleteRelatedJobs=false] removes all queued jobs releated to the worker if set to true\n */\n removeWorker(name: string, deleteRelatedJobs = false) {\n delete this.workers[name];\n if (deleteRelatedJobs) {\n this.jobStore.removeJobsByWorkerName(name);\n }\n }\n\n /**\n * adds a job to the queue\n * @param workerName name of the worker which should be used to excute the job\n * @param [payload={}] payload which is passed as parameter to the executer\n * @param [options={ attempts: 0, timeout: 0, priority: 0 }] options to set max attempts, a timeout and a priority\n * @param [startQueue=true] if set to false the queue won't start automaticly when adding a job\n * @returns job id\n */\n addJob

(\n workerName: string,\n payload: P,\n options = { attempts: 0, timeout: 0, priority: 0 },\n startQueue = true\n ) {\n const { attempts = 0, timeout = 0, priority = 0 } = options;\n const id: string = Uuid.v4();\n const job: RawJob = {\n id,\n payload: JSON.stringify(payload || {}),\n metaData: JSON.stringify({ failedAttempts: 0, errors: [] }),\n active: FALSE,\n created: new Date().toISOString(),\n failed: '',\n workerName,\n attempts,\n timeout,\n priority,\n isDeleted: false,\n status: \"idle\"\n };\n if (!this.workers[job.workerName]) {\n throw new QueueError(`Missing worker with name ${job.workerName}`);\n }\n\n this.jobStore.addJob(job);\n this.emit('jobAdded', job);\n if (startQueue && !this.isActive) {\n this.start();\n }\n\n return id;\n }\n /**\n * starts the queue to execute queued jobs\n */\n async start() {\n if (!this.isActive) {\n this.isActive = true;\n this.executedJobs = [];\n await this.resetActiveJobs();\n this.scheduleQueue();\n }\n }\n /**\n * stop the queue from executing queued jobs\n */\n stop() {\n this.isActive = false;\n }\n\n /**\n * cancel running job\n */\n cancelJob(jobId: string, exception?: Error) {\n const promise = this.runningJobPromises[jobId];\n if (promise !== undefined && typeof promise[CANCEL] === 'function') {\n promise[CANCEL](exception || new QueueError(`job canceled`, \"cancelled\"));\n } else if (!promise[CANCEL]) {\n console.warn('Worker does not have a cancel method implemented');\n } else {\n throw new QueueError(`Job with id ${jobId} not currently running`, \"error\");\n }\n }\n async cancelAllActiveJobs() {\n const jobs = await this.jobStore.getActiveMarkedJobs()\n\n jobs.forEach((job) => {\n const newJob = { ...job, ...{ active: FALSE, status: \"cancelled\" } };\n const isRunning = this.runningJobPromises[job.id];\n // eslint-disable-next-line @typescript-eslint/no-misused-promises\n if (!!Boolean(isRunning)) {\n this.cancelJob(job.id, new QueueError(`Job with id ${job.id} cancelled`, \"cancelled\"));\n }\n this.jobStore.updateJob(newJob as RawJob);\n this.emit('jobCancelled', newJob as RawJob);\n })\n }\n cancelActiveJob(job: RawJob) {\n const newJob = { ...job, ...{ active: FALSE, status: \"cancelled\" } };\n\n const isRunning = this.runningJobPromises[job.id];\n // eslint-disable-next-line @typescript-eslint/no-misused-promises\n if (!!isRunning) {\n this.cancelJob(job.id, new QueueError(`Job with id ${job.id} cancelled`, \"cancelled\"));\n }\n\n this.jobStore.updateJob(newJob as RawJob);\n\n this.emit('jobCancelled', newJob as RawJob);\n }\n\n private resetActiveJob = (job: RawJob) => {\n this.jobStore.updateJob({ ...job, ...{ active: FALSE } });\n };\n private async resetActiveJobs() {\n const activeMarkedJobs = await this.jobStore.getActiveMarkedJobs();\n const resetTasks = activeMarkedJobs.map(this.resetActiveJob);\n await Promise.all(resetTasks);\n }\n private scheduleQueue() {\n if (AppState.currentState === 'active' && Platform.OS === \"ios\") {\n this.timeoutId = setTimeout(this.runQueue, this.updateInterval);\n } else {\n this.runQueue();\n }\n }\n private runQueue = async () => {\n if (!this.isActive) {\n this.finishQueue();\n return;\n }\n const nextJob = await this.jobStore.getNextJob();\n if (this.isJobNotEmpty(nextJob)) {\n const nextJobs = await this.getJobsForWorker(nextJob.workerName);\n const processingJobs = nextJobs.map(async (job) => this.limitExecution(this.excuteJob, job));\n await Promise.all(processingJobs);\n } else if (!this.isExecuting()) {\n this.finishQueue();\n return;\n }\n this.scheduleQueue();\n };\n\n private isJobNotEmpty(rawJob: RawJob | {}) {\n return Object.keys(rawJob).length > 0;\n }\n\n private limitExecution = async (executer: (rawJob: RawJob) => Promise, rawJob: RawJob) => {\n return new Promise(async (resolve) => await this.enqueueJobExecuter(executer, resolve, rawJob));\n };\n\n private enqueueJobExecuter = async (\n executer: (rawJob: RawJob) => Promise,\n resolve: (_: unknown) => void,\n rawJob: RawJob\n ) => {\n if (this.isExecuterAvailable()) {\n await this.runExecuter(executer, resolve, rawJob);\n } else {\n this.queuedJobExecuter.push(this.runExecuter.bind(null, executer, resolve, rawJob));\n }\n };\n\n private runExecuter = async (\n executer: (rawJob: RawJob) => Promise,\n resolve: (_: unknown) => void,\n rawJob: RawJob\n ) => {\n try {\n await executer(rawJob);\n } finally {\n resolve(true);\n if (this.queuedJobExecuter.length > 0 && this.isExecuterAvailable()) {\n await this.queuedJobExecuter.shift()();\n }\n }\n };\n private isExecuterAvailable() {\n return this.concurrency <= 0 || this.activeJobCount < this.concurrency;\n }\n private isExecuting() {\n return this.activeJobCount > 0;\n }\n\n private finishQueue() {\n this.onQueueFinish(this.executedJobs);\n this.isActive = false;\n clearTimeout(this.timeoutId);\n }\n\n async getJobsForWorker(workerName: string) {\n const { isBusy, availableExecuters } = this.workers[workerName];\n if (!isBusy) {\n return await this.jobStore.getJobsForWorker(workerName, availableExecuters);\n } else {\n return await this.getJobsForAlternateWorker();\n }\n }\n\n async getJobsForWorkerWithDeleted(workerName: string) {\n const { isBusy, availableExecuters } = this.workers[workerName];\n if (!isBusy) {\n return await this.jobStore.getJobsForWorkerWithDeleted(workerName, availableExecuters);\n } else {\n return await this.getJobsForAlternateWorker();\n }\n }\n\n private async getJobsForAlternateWorker() {\n for (const workerName of Object.keys(this.workers)) {\n const { isBusy, availableExecuters } = this.workers[workerName];\n let nextJobs: RawJob[] = [];\n if (!isBusy) {\n nextJobs = await this.jobStore.getJobsForWorker(workerName, availableExecuters);\n }\n if (nextJobs.length > 0) {\n return nextJobs;\n }\n }\n return [];\n }\n\n private excuteJob = async (rawJob: RawJob) => {\n const worker = this.workers[rawJob.workerName];\n const payload = JSON.parse(rawJob.payload) as Worker;\n const job = { ...rawJob, ...{ payload } } as Job;\n\n try {\n job.status = \"processing\";\n this.jobStore.updateJob({ ...job, payload: JSON.stringify(payload) });\n this.emit('jobStarted', job);\n\n this.activeJobCount++;\n if (!this.workers[rawJob.workerName]) {\n throw new QueueError(`Missing worker with name ${rawJob.workerName}`, \"error\");\n }\n const promise = worker.execute(rawJob);\n\n this.runningJobPromises[rawJob.id] = promise;\n await promise;\n\n worker.triggerSuccess(job);\n job.status = \"finished\";\n this.jobStore.updateJob({ ...job, payload: JSON.stringify(payload) });\n this.jobStore.removeJob(rawJob);\n this.emit('jobSucceeded', job);\n } catch (err) {\n const error = err as QueueError;\n const { attempts } = rawJob;\n // eslint-disable-next-line prefer-const\n let { errors, failedAttempts } = JSON.parse(rawJob.metaData) as { errors: string[]; failedAttempts: number };\n failedAttempts++;\n let failed = '';\n if (failedAttempts >= attempts) {\n failed = new Date().toISOString();\n }\n const metaData = JSON.stringify({ errors: [...errors, error], failedAttempts });\n worker.triggerFailure({ ...job, metaData, failed }, error);\n const failedJob = { ...rawJob, ...{ active: FALSE, metaData, failed, status: error.code === \"cancelled\" ? \"cancelled\" : \"failed\" } } as RawJob;\n this.jobStore.updateJob(failedJob);\n this.emit('jobFailed', failedJob, error);\n } finally {\n delete this.runningJobPromises[job.id];\n worker.decreaseExecutionCount();\n worker.triggerCompletion(job);\n this.emit('jobCompleted', { ...job });\n this.executedJobs.push(rawJob);\n this.activeJobCount--;\n }\n };\n}\nexport default Queue.instance;\n"],"mappings":";;;;AAAA;AACA;AACA,SAASA,QAAQ,EAAEC,aAAa,EAAEC,QAAQ,QAAQ,cAAc;AAEhE,SAASC,KAAK,EAAeC,IAAI,QAAQ,cAAc;AAEvD,SAASC,IAAI,QAAQ,cAAc;AACnC,SAAiBC,MAAM,QAA4B,UAAU;AAG7D,OAAOC,YAAY,MAAM,eAAe;AAIxC,OAAO,MAAMC,UAAU,SAASC,KAAK,CAAC;EAElCC,WAAWA,CAACC,OAAe,EAAEC,IAAoB,GAAG,OAAO,EAAE;IACzD,KAAK,CAACD,OAAO,CAAC;IAACE,eAAA;IACf,IAAI,CAACC,IAAI,GAAG,YAAY;IACxB,IAAI,CAACF,IAAI,GAAGA,IAAI;EACpB;AACJ;;AAEA;AACA;AACA;;AAkDA;AACA;AACA;;AAaA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,MAAMG,KAAK,SAASR,YAAY,CAAc;EACjD,WAAWS,QAAQA,CAAA,EAAG;IAClB,IAAI,IAAI,CAACC,aAAa,EAAE;MACpB,OAAO,IAAI,CAACA,aAAa;IAC7B,CAAC,MAAM;MACH,IAAI,CAACA,aAAa,GAAG,IAAIF,KAAK,CAAC,CAAC;MAChC,OAAO,IAAI,CAACE,aAAa;IAC7B;EACJ;EACA;AACJ;AACA;EACI,IAAIC,SAASA,CAAA,EAAG;IACZ,OAAO,IAAI,CAACC,QAAQ;EACxB;EACA;AACJ;AACA;EACI,IAAIC,iBAAiBA,CAAA,EAAG;IACpB,OAAO,IAAI,CAACC,OAAO;EACvB;EAmBQX,WAAWA,CAAA,EAAG;IAClB,KAAK,CAAC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