@bull-monitor/root
Advanced tools
Comparing version 0.4.1 to 0.5.0
import { DataSource } from 'apollo-datasource'; | ||
import type { Queue as BullQueue, JobCounts, JobStatus, JobId } from 'bull'; | ||
import { CreateJobInput, MutationCleanQueueArgs, MutationCloseQueueArgs, MutationDiscardJobArgs, MutationEmptyQueueArgs, MutationLogArgs, MutationMoveJobToCompletedArgs, MutationMoveJobToFailedArgs, MutationPromoteJobArgs, MutationRemoveJobArgs, MutationRemoveJobsByPatternArgs, MutationResumeQueueArgs, MutationRetryJobArgs, MutationUpdateJobDataArgs, OrderEnum } from '../../typings/gql'; | ||
import { Maybe } from '../../typings/utils'; | ||
import redisInfo from 'redis-info'; | ||
declare type Maybe<T> = T | undefined; | ||
export declare class BullMonitorError extends Error { | ||
constructor(msg: any); | ||
} | ||
export declare enum ErrorEnum { | ||
QUEUE_NOT_FOUND = "QUEUE_NOT_FOUND", | ||
JOB_NOT_FOUND = "JOB_NOT_FOUND" | ||
} | ||
export declare class BullDataSource extends DataSource { | ||
@@ -11,5 +18,7 @@ private _queues; | ||
private _convertQueuesToMap; | ||
getQueueByName(name: string): BullQueue<any> | undefined; | ||
private _throwInternalError; | ||
private _throwQueueNotFound; | ||
private _throwJobNotFound; | ||
getQueueByName(name: string, throwIfNotFound?: boolean): BullQueue<any> | undefined; | ||
getQueues(): BullQueue[]; | ||
createJob({ queue: queueName, name, data, options, }: CreateJobInput): Promise<import("bull").Job<any> | undefined>; | ||
getQueueJobs({ queue, limit, offset, status, id, order, }: { | ||
@@ -23,3 +32,3 @@ status: JobStatus[]; | ||
}): Promise<import("bull").Job<any>[] | undefined>; | ||
getJob(queueName: string, id: JobId): Promise<import("bull").Job<any> | null | undefined>; | ||
getJob(queueName: string, id: JobId, throwIfNotFound?: boolean): Promise<import("bull").Job<any> | null | undefined>; | ||
getJobLogs(queueName: string, id: number): Promise<{ | ||
@@ -29,16 +38,3 @@ logs: string[]; | ||
} | undefined>; | ||
createJobLog(args: MutationLogArgs): Promise<import("bull").Job<any> | null | undefined>; | ||
retryJob(args: MutationRetryJobArgs): Promise<import("bull").Job<any> | null | undefined>; | ||
removeJobById(args: MutationRemoveJobArgs): Promise<import("bull").Job<any> | null | undefined>; | ||
moveJobToCompleted(args: MutationMoveJobToCompletedArgs): Promise<import("bull").Job<any> | null | undefined>; | ||
moveJobToFailed(args: MutationMoveJobToFailedArgs): Promise<import("bull").Job<any> | null | undefined>; | ||
promoteJob(args: MutationPromoteJobArgs): Promise<import("bull").Job<any> | null | undefined>; | ||
discardJob(args: MutationDiscardJobArgs): Promise<import("bull").Job<any> | null | undefined>; | ||
updateJobData(args: MutationUpdateJobDataArgs): Promise<import("bull").Job<any> | null | undefined>; | ||
getQueueJobsCounts(name: string): Promise<Maybe<JobCounts>>; | ||
pauseQueue(name: string): Promise<BullQueue<any> | undefined>; | ||
cleanQueue(args: MutationCleanQueueArgs): Promise<import("bull").Job<any>[] | undefined>; | ||
emptyQueue(args: MutationEmptyQueueArgs): Promise<BullQueue<any> | undefined>; | ||
closeQueue(args: MutationCloseQueueArgs): Promise<BullQueue<any> | undefined>; | ||
resumeQueue(args: MutationResumeQueueArgs): Promise<BullQueue<any> | undefined>; | ||
getQueueFailedCount(name: string): Promise<Maybe<number>>; | ||
@@ -51,5 +47,18 @@ getQueueCompletedCount(name: string): Promise<Maybe<number>>; | ||
getQueueWaitingOrDelayedJobsCount(name: string): Promise<Maybe<number>>; | ||
getRedisInfo(): Promise<redisInfo.RedisInfo | null>; | ||
createJob({ queue: queueName, name, data, options, }: CreateJobInput): Promise<import("bull").Job<any> | undefined>; | ||
removeJobsByPattern(args: MutationRemoveJobsByPatternArgs): Promise<boolean>; | ||
getRedisInfo(): Promise<redisInfo.RedisInfo | null>; | ||
pauseQueue(name: string): Promise<BullQueue<any> | undefined>; | ||
cleanQueue(args: MutationCleanQueueArgs): Promise<import("bull").Job<any>[] | undefined>; | ||
emptyQueue(args: MutationEmptyQueueArgs): Promise<BullQueue<any> | undefined>; | ||
closeQueue(args: MutationCloseQueueArgs): Promise<BullQueue<any> | undefined>; | ||
resumeQueue(args: MutationResumeQueueArgs): Promise<BullQueue<any> | undefined>; | ||
promoteJob(args: MutationPromoteJobArgs): Promise<import("bull").Job<any> | null | undefined>; | ||
discardJob(args: MutationDiscardJobArgs): Promise<import("bull").Job<any> | null | undefined>; | ||
updateJobData(args: MutationUpdateJobDataArgs): Promise<import("bull").Job<any> | null | undefined>; | ||
createJobLog(args: MutationLogArgs): Promise<import("bull").Job<any> | null | undefined>; | ||
retryJob(args: MutationRetryJobArgs): Promise<import("bull").Job<any> | null | undefined>; | ||
removeJobById(args: MutationRemoveJobArgs): Promise<import("bull").Job<any> | null | undefined>; | ||
moveJobToCompleted(args: MutationMoveJobToCompletedArgs): Promise<import("bull").Job<any> | null | undefined>; | ||
moveJobToFailed(args: MutationMoveJobToFailedArgs): Promise<import("bull").Job<any> | null | undefined>; | ||
} | ||
export {}; |
@@ -15,3 +15,3 @@ "use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.BullDataSource = void 0; | ||
exports.BullDataSource = exports.ErrorEnum = exports.BullMonitorError = void 0; | ||
const apollo_datasource_1 = require("apollo-datasource"); | ||
@@ -21,2 +21,14 @@ const json_1 = require("../../services/json"); | ||
const redis_info_1 = __importDefault(require("redis-info")); | ||
class BullMonitorError extends Error { | ||
constructor(msg) { | ||
super(msg); | ||
this.name = 'BullMonitorError'; | ||
} | ||
} | ||
exports.BullMonitorError = BullMonitorError; | ||
var ErrorEnum; | ||
(function (ErrorEnum) { | ||
ErrorEnum["QUEUE_NOT_FOUND"] = "QUEUE_NOT_FOUND"; | ||
ErrorEnum["JOB_NOT_FOUND"] = "JOB_NOT_FOUND"; | ||
})(ErrorEnum = exports.ErrorEnum || (exports.ErrorEnum = {})); | ||
class BullDataSource extends apollo_datasource_1.DataSource { | ||
@@ -34,17 +46,25 @@ constructor(_queues) { | ||
} | ||
getQueueByName(name) { | ||
return this._queuesMap.get(name); | ||
_throwInternalError(e) { | ||
throw new BullMonitorError(e); | ||
} | ||
_throwQueueNotFound() { | ||
this._throwInternalError(ErrorEnum.QUEUE_NOT_FOUND); | ||
} | ||
_throwJobNotFound() { | ||
this._throwInternalError(ErrorEnum.JOB_NOT_FOUND); | ||
} | ||
// queries | ||
getQueueByName(name, throwIfNotFound) { | ||
const queue = this._queuesMap.get(name); | ||
if (!queue && throwIfNotFound) { | ||
this._throwQueueNotFound(); | ||
} | ||
return queue; | ||
} | ||
getQueues() { | ||
return this._queues; | ||
} | ||
createJob({ queue: queueName, name = null, data = {}, options = {}, }) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
const queue = this._queuesMap.get(queueName); | ||
return yield (queue === null || queue === void 0 ? void 0 : queue.add(name, json_1.JsonService.maybeParse(data), json_1.JsonService.maybeParse(options))); | ||
}); | ||
} | ||
getQueueJobs({ queue, limit = 20, offset = 0, status = [], id, order = gql_1.OrderEnum.Desc, }) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
const bullQueue = this.getQueueByName(queue); | ||
const bullQueue = this.getQueueByName(queue, true); | ||
if (id) { | ||
@@ -57,6 +77,10 @@ const job = yield (bullQueue === null || bullQueue === void 0 ? void 0 : bullQueue.getJob(id)); | ||
} | ||
getJob(queueName, id) { | ||
getJob(queueName, id, throwIfNotFound) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
const queue = this.getQueueByName(queueName); | ||
return queue === null || queue === void 0 ? void 0 : queue.getJob(id); | ||
const queue = this.getQueueByName(queueName, true); | ||
const job = queue === null || queue === void 0 ? void 0 : queue.getJob(id); | ||
if (!job && throwIfNotFound) { | ||
this._throwJobNotFound(); | ||
} | ||
return job; | ||
}); | ||
@@ -66,73 +90,81 @@ } | ||
return __awaiter(this, void 0, void 0, function* () { | ||
const queue = this.getQueueByName(queueName); | ||
const queue = this.getQueueByName(queueName, true); | ||
return yield (queue === null || queue === void 0 ? void 0 : queue.getJobLogs(id)); | ||
}); | ||
} | ||
createJobLog(args) { | ||
getQueueJobsCounts(name) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
const job = yield this.getJob(args.queue, args.id); | ||
yield (job === null || job === void 0 ? void 0 : job.log(args.row)); | ||
return job; | ||
const queue = this.getQueueByName(name); | ||
return yield (queue === null || queue === void 0 ? void 0 : queue.getJobCounts()); | ||
}); | ||
} | ||
retryJob(args) { | ||
getQueueFailedCount(name) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
const job = yield this.getJob(args.queue, args.id); | ||
yield (job === null || job === void 0 ? void 0 : job.retry()); | ||
return job; | ||
const queue = this.getQueueByName(name); | ||
return yield (queue === null || queue === void 0 ? void 0 : queue.getFailedCount()); | ||
}); | ||
} | ||
removeJobById(args) { | ||
getQueueCompletedCount(name) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
const job = yield this.getJob(args.queue, args.id); | ||
yield (job === null || job === void 0 ? void 0 : job.remove()); | ||
return job; | ||
const queue = this.getQueueByName(name); | ||
return yield (queue === null || queue === void 0 ? void 0 : queue.getCompletedCount()); | ||
}); | ||
} | ||
moveJobToCompleted(args) { | ||
getQueueDelayedCount(name) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
const job = yield this.getJob(args.queue, args.id); | ||
yield (job === null || job === void 0 ? void 0 : job.moveToCompleted()); | ||
return job; | ||
const queue = this.getQueueByName(name); | ||
return yield (queue === null || queue === void 0 ? void 0 : queue.getDelayedCount()); | ||
}); | ||
} | ||
moveJobToFailed(args) { | ||
getQueueActiveCount(name) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
const job = yield this.getJob(args.queue, args.id); | ||
yield (job === null || job === void 0 ? void 0 : job.moveToFailed({ | ||
message: '', | ||
})); | ||
return job; | ||
const queue = this.getQueueByName(name); | ||
return yield (queue === null || queue === void 0 ? void 0 : queue.getActiveCount()); | ||
}); | ||
} | ||
promoteJob(args) { | ||
getQueueWaitingCount(name) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
const job = yield this.getJob(args.queue, args.id); | ||
yield (job === null || job === void 0 ? void 0 : job.promote()); | ||
return job; | ||
const queue = this.getQueueByName(name); | ||
return yield (queue === null || queue === void 0 ? void 0 : queue.getWaitingCount()); | ||
}); | ||
} | ||
discardJob(args) { | ||
getQueuePausedCount(name) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
const job = yield this.getJob(args.queue, args.id); | ||
yield (job === null || job === void 0 ? void 0 : job.discard()); | ||
return job; | ||
const queue = this.getQueueByName(name); | ||
return yield (queue === null || queue === void 0 ? void 0 : queue.getPausedCount()); | ||
}); | ||
} | ||
updateJobData(args) { | ||
getQueueWaitingOrDelayedJobsCount(name) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
const job = yield this.getJob(args.queue, args.id); | ||
yield (job === null || job === void 0 ? void 0 : job.update(json_1.JsonService.maybeParse(args.data))); | ||
return job; | ||
const queue = this.getQueueByName(name); | ||
return yield (queue === null || queue === void 0 ? void 0 : queue.count()); | ||
}); | ||
} | ||
getQueueJobsCounts(name) { | ||
getRedisInfo() { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
const queue = this.getQueueByName(name); | ||
return yield (queue === null || queue === void 0 ? void 0 : queue.getJobCounts()); | ||
if (this._queuesMap.size > 0) { | ||
const firstQueue = this._queues[0]; | ||
const rawInfo = yield firstQueue.client.info(); | ||
return redis_info_1.default.parse(rawInfo); | ||
} | ||
return null; | ||
}); | ||
} | ||
// mutations | ||
createJob({ queue: queueName, name = null, data = {}, options = {}, }) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
const queue = this.getQueueByName(queueName, true); | ||
return yield (queue === null || queue === void 0 ? void 0 : queue.add(name, json_1.JsonService.maybeParse(data), json_1.JsonService.maybeParse(options))); | ||
}); | ||
} | ||
removeJobsByPattern(args) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
const queue = this.getQueueByName(args.queue, true); | ||
yield (queue === null || queue === void 0 ? void 0 : queue.removeJobs(args.pattern)); | ||
return true; | ||
}); | ||
} | ||
pauseQueue(name) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
const queue = this.getQueueByName(name); | ||
const queue = this.getQueueByName(name, true); | ||
yield (queue === null || queue === void 0 ? void 0 : queue.pause()); | ||
@@ -144,3 +176,3 @@ return queue; | ||
return __awaiter(this, void 0, void 0, function* () { | ||
const queue = this.getQueueByName(args.queue); | ||
const queue = this.getQueueByName(args.queue, true); | ||
return yield (queue === null || queue === void 0 ? void 0 : queue.clean(args.grace, args.status)); | ||
@@ -151,3 +183,3 @@ }); | ||
return __awaiter(this, void 0, void 0, function* () { | ||
const queue = this.getQueueByName(args.queue); | ||
const queue = this.getQueueByName(args.queue, true); | ||
yield (queue === null || queue === void 0 ? void 0 : queue.empty()); | ||
@@ -159,3 +191,3 @@ return queue; | ||
return __awaiter(this, void 0, void 0, function* () { | ||
const queue = this.getQueueByName(args.queue); | ||
const queue = this.getQueueByName(args.queue, true); | ||
yield (queue === null || queue === void 0 ? void 0 : queue.close()); | ||
@@ -167,3 +199,3 @@ return queue; | ||
return __awaiter(this, void 0, void 0, function* () { | ||
const queue = this.getQueueByName(args.queue); | ||
const queue = this.getQueueByName(args.queue, true); | ||
yield (queue === null || queue === void 0 ? void 0 : queue.resume()); | ||
@@ -173,63 +205,62 @@ return queue; | ||
} | ||
getQueueFailedCount(name) { | ||
promoteJob(args) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
const queue = this.getQueueByName(name); | ||
return yield (queue === null || queue === void 0 ? void 0 : queue.getFailedCount()); | ||
const job = yield this.getJob(args.queue, args.id, true); | ||
yield (job === null || job === void 0 ? void 0 : job.promote()); | ||
return job; | ||
}); | ||
} | ||
getQueueCompletedCount(name) { | ||
discardJob(args) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
const queue = this.getQueueByName(name); | ||
return yield (queue === null || queue === void 0 ? void 0 : queue.getCompletedCount()); | ||
const job = yield this.getJob(args.queue, args.id, true); | ||
yield (job === null || job === void 0 ? void 0 : job.discard()); | ||
return job; | ||
}); | ||
} | ||
getQueueDelayedCount(name) { | ||
updateJobData(args) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
const queue = this.getQueueByName(name); | ||
return yield (queue === null || queue === void 0 ? void 0 : queue.getDelayedCount()); | ||
const job = yield this.getJob(args.queue, args.id, true); | ||
yield (job === null || job === void 0 ? void 0 : job.update(json_1.JsonService.maybeParse(args.data))); | ||
return job; | ||
}); | ||
} | ||
getQueueActiveCount(name) { | ||
createJobLog(args) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
const queue = this.getQueueByName(name); | ||
return yield (queue === null || queue === void 0 ? void 0 : queue.getActiveCount()); | ||
const job = yield this.getJob(args.queue, args.id, true); | ||
yield (job === null || job === void 0 ? void 0 : job.log(args.row)); | ||
return job; | ||
}); | ||
} | ||
getQueueWaitingCount(name) { | ||
retryJob(args) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
const queue = this.getQueueByName(name); | ||
return yield (queue === null || queue === void 0 ? void 0 : queue.getWaitingCount()); | ||
const job = yield this.getJob(args.queue, args.id, true); | ||
yield (job === null || job === void 0 ? void 0 : job.retry()); | ||
return job; | ||
}); | ||
} | ||
getQueuePausedCount(name) { | ||
removeJobById(args) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
const queue = this.getQueueByName(name); | ||
return yield (queue === null || queue === void 0 ? void 0 : queue.getPausedCount()); | ||
const job = yield this.getJob(args.queue, args.id, true); | ||
yield (job === null || job === void 0 ? void 0 : job.remove()); | ||
return job; | ||
}); | ||
} | ||
getQueueWaitingOrDelayedJobsCount(name) { | ||
moveJobToCompleted(args) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
const queue = this.getQueueByName(name); | ||
return yield (queue === null || queue === void 0 ? void 0 : queue.count()); | ||
const job = yield this.getJob(args.queue, args.id, true); | ||
yield (job === null || job === void 0 ? void 0 : job.moveToCompleted()); | ||
return job; | ||
}); | ||
} | ||
removeJobsByPattern(args) { | ||
moveJobToFailed(args) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
const queue = this.getQueueByName(args.queue); | ||
yield (queue === null || queue === void 0 ? void 0 : queue.removeJobs(args.pattern)); | ||
return true; | ||
const job = yield this.getJob(args.queue, args.id, true); | ||
yield (job === null || job === void 0 ? void 0 : job.moveToFailed({ | ||
message: '', | ||
})); | ||
return job; | ||
}); | ||
} | ||
getRedisInfo() { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
if (this._queuesMap.size > 0) { | ||
const firstQueue = this._queues[0]; | ||
const rawInfo = yield firstQueue.client.info(); | ||
return redis_info_1.default.parse(rawInfo); | ||
} | ||
return null; | ||
}); | ||
} | ||
} | ||
exports.BullDataSource = BullDataSource; | ||
//# sourceMappingURL=bull.js.map |
@@ -1,2 +0,2 @@ | ||
import { Queue } from 'bull'; | ||
import type { Queue } from 'bull'; | ||
import type { ApolloServerBase, Config as ApolloConfig } from 'apollo-server-core'; | ||
@@ -3,0 +3,0 @@ export declare type Config = { |
{ | ||
"name": "@bull-monitor/root", | ||
"version": "0.4.1", | ||
"version": "0.5.0", | ||
"repository": { | ||
@@ -37,3 +37,3 @@ "type": "git", | ||
}, | ||
"gitHead": "9c55cea468d7d2a3bd316fc4516798c24f304697" | ||
"gitHead": "251ce058d72c00fdcbde8296eb4361d41c7a5da2" | ||
} |
Sorry, the diff of this file is not supported yet
68256
63
1265