@bull-board/api
Version:
A Dashboard server API built on top of bull or bullmq.
101 lines • 3.1 kB
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.BullAdapter = void 0;
const bull_1 = __importDefault(require("bull"));
const statuses_1 = require("../constants/statuses");
const base_1 = require("./base");
class BullAdapter extends base_1.BaseAdapter {
constructor(queue, options = {}) {
super('bull', { ...options, allowCompletedRetries: false });
this.queue = queue;
if (!(queue instanceof bull_1.default)) {
throw new Error(`You've used the Bull adapter with a non-Bull queue.`);
}
}
getRedisInfo() {
return this.queue.client.info();
}
getName() {
return `${this.prefix}${this.queue.name}`;
}
clean(jobStatus, graceTimeMs) {
return this.queue.clean(graceTimeMs, jobStatus);
}
addJob(name, data, options) {
return this.queue.add(name, data, options);
}
async getJob(id) {
const job = await this.queue.getJob(id);
return job && this.alignJobData(job);
}
async getJobs(jobStatuses, start, end) {
const jobs = await this.queue.getJobs(jobStatuses, start, end);
return jobs.map(this.alignJobData);
}
getJobCounts() {
return this.queue.getJobCounts();
}
getJobLogs(id) {
return this.queue.getJobLogs(id).then(({ logs }) => logs);
}
isPaused() {
return this.queue.isPaused();
}
pause() {
return this.queue.pause();
}
resume() {
return this.queue.resume();
}
empty() {
return this.queue.empty();
}
obliterate() {
return this.queue.obliterate({ force: false });
}
async promoteAll() {
const jobs = await this.getJobs([statuses_1.STATUSES.delayed]);
await Promise.all(jobs.map((job) => job.promote()));
}
async removeJobScheduler(_id) {
return false;
}
getStatuses() {
return [
statuses_1.STATUSES.latest,
statuses_1.STATUSES.active,
statuses_1.STATUSES.waiting,
statuses_1.STATUSES.completed,
statuses_1.STATUSES.failed,
statuses_1.STATUSES.delayed,
statuses_1.STATUSES.paused,
];
}
getJobStatuses() {
return [
statuses_1.STATUSES.active,
statuses_1.STATUSES.waiting,
statuses_1.STATUSES.completed,
statuses_1.STATUSES.failed,
statuses_1.STATUSES.delayed,
statuses_1.STATUSES.paused,
];
}
async getGlobalConcurrency() {
return null;
}
async setGlobalConcurrency(_concurrency) {
// Bull does not support global concurrency
}
alignJobData(job) {
if (typeof (job === null || job === void 0 ? void 0 : job.attemptsMade) === 'number') {
job.attemptsMade++;
}
return job;
}
}
exports.BullAdapter = BullAdapter;
//# sourceMappingURL=bull.js.map