UNPKG

@cavai/adonis-queue

Version:
51 lines (50 loc) 1.34 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.Dispatcher = void 0; class Dispatcher { then(onfulfilled, onrejected) { return this.exec().then(onfulfilled, onrejected); } catch(onrejected) { return this.exec().catch(onrejected); } finally(onfinally) { return this.exec().finally(onfinally); } /** * Required when Promises are extended */ get [Symbol.toStringTag]() { return this.constructor.name; } constructor(job, data) { this.job = job; this.data = data; } /** * Execute promise, storing job to storage using defined driver */ async exec() { if (!this.job.classPath) { throw new Error(`classPath param missing in ${this.job.name}`); } let payload = { classPath: this.job.classPath, data: this.data, version: 'v1', }; return this.job.queueManager.store(this.job.classPath, payload, { availableAt: this.availableAt, }); } /** * Delay job execution until given time * * @param time Time after what job will be available for execution */ delay(time) { this.availableAt = time; return this; } } exports.Dispatcher = Dispatcher;