Comparing version
74
index.js
@@ -17,3 +17,3 @@ #!/usr/bin/env node | ||
.option("-r, --redis <redis>", "host:port of redis, default localhost:6379") | ||
.action((async ({ queue: name, options }) => { | ||
.action(utils_1.wrapTryCatch(async ({ queue: name, options }) => { | ||
const url = options.redis | ||
@@ -27,6 +27,6 @@ ? `redis://${options.redis}` | ||
})); | ||
exports.vorpal.command("stats", "count of jobs by groups").action(async () => { | ||
exports.vorpal.command("stats", "count of jobs by groups").action(utils_1.wrapTryCatch(async () => { | ||
const queue = await queue_1.getQueue(); | ||
console.table(await queue.getJobCounts()); | ||
}); | ||
})); | ||
exports.vorpal | ||
@@ -36,3 +36,3 @@ .command("active", "fetch active jobs") | ||
.option("-ta, --timeAgo <timeAgo>", `get jobs since time ago via ${utils_1.msLink}`) | ||
.action(async ({ options }) => { | ||
.action(utils_1.wrapTryCatch(async ({ options }) => { | ||
const queue = await queue_1.getQueue(); | ||
@@ -42,3 +42,3 @@ const filter = await utils_1.getFilter(options.filter); | ||
utils_1.showJobs(await queue.getActive(), { ...filter, ...timeAgoFilter }); | ||
}); | ||
})); | ||
exports.vorpal | ||
@@ -48,3 +48,3 @@ .command("waiting", "fetch waiting jobs") | ||
.option("-ta, --timeAgo <timeAgo>", `get jobs since time ago via ${utils_1.msLink}`) | ||
.action(async ({ options }) => { | ||
.action(utils_1.wrapTryCatch(async ({ options }) => { | ||
const queue = await queue_1.getQueue(); | ||
@@ -54,3 +54,3 @@ const filter = await utils_1.getFilter(options.filter); | ||
utils_1.showJobs(await queue.getWaiting(), { ...filter, ...timeAgoFilter }); | ||
}); | ||
})); | ||
exports.vorpal | ||
@@ -60,3 +60,3 @@ .command("completed", "fetch completed jobs") | ||
.option("-ta, --timeAgo <timeAgo>", `get jobs since time ago via ${utils_1.msLink}`) | ||
.action(async ({ options }) => { | ||
.action(utils_1.wrapTryCatch(async ({ options }) => { | ||
const queue = await queue_1.getQueue(); | ||
@@ -66,3 +66,3 @@ const filter = await utils_1.getFilter(options.filter); | ||
utils_1.showJobs(await queue.getCompleted(), { ...filter, ...timeAgoFilter }); | ||
}); | ||
})); | ||
exports.vorpal | ||
@@ -72,3 +72,3 @@ .command("failed", "fetch failed jobs") | ||
.option("-ta, --timeAgo <timeAgo>", `get jobs since time ago via ${utils_1.msLink}`) | ||
.action(async ({ options }) => { | ||
.action(utils_1.wrapTryCatch(async ({ options }) => { | ||
const queue = await queue_1.getQueue(); | ||
@@ -78,3 +78,3 @@ const filter = await utils_1.getFilter(options.filter); | ||
utils_1.showJobs(await queue.getFailed(), { ...filter, ...timeAgoFilter }); | ||
}); | ||
})); | ||
exports.vorpal | ||
@@ -84,3 +84,3 @@ .command("delayed", "fetch delayed jobs") | ||
.option("-ta, --timeAgo <timeAgo>", `get jobs since time ago via ${utils_1.msLink}`) | ||
.action(async ({ options }) => { | ||
.action(utils_1.wrapTryCatch(async ({ options }) => { | ||
const queue = await queue_1.getQueue(); | ||
@@ -90,4 +90,4 @@ const filter = await utils_1.getFilter(options.filter); | ||
utils_1.showJobs(await queue.getDelayed(), { ...filter, ...timeAgoFilter }); | ||
}); | ||
exports.vorpal.command("get <jobId...>", "get job").action((async ({ jobId }) => { | ||
})); | ||
exports.vorpal.command("get <jobId...>", "get job").action(utils_1.wrapTryCatch(async ({ jobId }) => { | ||
const { notFoundIds, foundJobs } = await utils_1.splitJobsByFound(jobId); | ||
@@ -100,3 +100,3 @@ notFoundIds.length && utils_1.logYellow(`Not found jobs: ${notFoundIds}`); | ||
.option("-n, --name <name>", "name for named job") | ||
.action(async function ({ data, options }) { | ||
.action(utils_1.wrapTryCatch(async function ({ data, options }) { | ||
const queue = await queue_1.getQueue(); | ||
@@ -114,6 +114,4 @@ let jobData; | ||
utils_1.logGreen(`Job with name '${jobName}', id '${addedJob.id}' added`); | ||
}); | ||
exports.vorpal | ||
.command("rm <jobId...>", "remove job") | ||
.action(async function ({ jobId }) { | ||
})); | ||
exports.vorpal.command("rm <jobId...>", "remove job").action(utils_1.wrapTryCatch(async function ({ jobId }) { | ||
await utils_1.answer(exports.vorpal, "Remove"); | ||
@@ -124,6 +122,4 @@ const { notFoundIds, foundJobs } = await utils_1.splitJobsByFound(jobId); | ||
foundJobs.length && utils_1.logGreen(`Jobs "${foundJobs.map(j => j.id)}" removed`); | ||
}); | ||
exports.vorpal | ||
.command("retry <jobId...>", "retry job") | ||
.action(async function ({ jobId }) { | ||
})); | ||
exports.vorpal.command("retry <jobId...>", "retry job").action(utils_1.wrapTryCatch(async function ({ jobId }) { | ||
await utils_1.answer(exports.vorpal, "Retry"); | ||
@@ -134,6 +130,4 @@ const { notFoundIds, foundJobs } = await utils_1.splitJobsByFound(jobId); | ||
foundJobs.length && utils_1.logGreen(`Jobs "${foundJobs.map(j => j.id)}" retried`); | ||
}); | ||
exports.vorpal | ||
.command("promote <jobId...>", "promote job") | ||
.action(async function ({ jobId }) { | ||
})); | ||
exports.vorpal.command("promote <jobId...>", "promote job").action(utils_1.wrapTryCatch(async function ({ jobId }) { | ||
await utils_1.answer(exports.vorpal, "Promote"); | ||
@@ -144,6 +138,4 @@ const { notFoundIds, foundJobs } = await utils_1.splitJobsByFound(jobId); | ||
foundJobs.length && utils_1.logGreen(`Jobs "${foundJobs.map(j => j.id)}" promoted`); | ||
}); | ||
exports.vorpal | ||
.command("fail <jobId> <reason>", "fail job") | ||
.action(async function ({ jobId, reason }) { | ||
})); | ||
exports.vorpal.command("fail <jobId> <reason>", "fail job").action(utils_1.wrapTryCatch(async function ({ jobId, reason }) { | ||
await queue_1.getQueue(); | ||
@@ -154,6 +146,4 @@ const job = await utils_1.getJob(jobId); | ||
utils_1.logGreen(`Job "${jobId}" failed`); | ||
}); | ||
exports.vorpal | ||
.command("complete <jobId> <data>", "complete job") | ||
.action(async function ({ jobId, data }) { | ||
})); | ||
exports.vorpal.command("complete <jobId> <data>", "complete job").action(utils_1.wrapTryCatch(async function ({ jobId, data }) { | ||
await queue_1.getQueue(); | ||
@@ -171,3 +161,3 @@ const job = await utils_1.getJob(jobId); | ||
utils_1.logGreen(`Job "${jobId}" completed`); | ||
}); | ||
})); | ||
exports.vorpal | ||
@@ -177,3 +167,3 @@ .command("clean <period>", `Clean queue for period ago, period format - ${utils_1.msLink}`) | ||
.option("-l, --limit <limit>", "Maximum amount of jobs to clean per call, default: all") | ||
.action(async function ({ period, options }) { | ||
.action(utils_1.wrapTryCatch(async function ({ period, options }) { | ||
const queue = await queue_1.getQueue(); | ||
@@ -194,3 +184,3 @@ await utils_1.answer(exports.vorpal, "Clean"); | ||
utils_1.logGreen(`Jobs cleaned`); | ||
}); | ||
})); | ||
exports.vorpal | ||
@@ -200,3 +190,3 @@ .command("logs <jobId>", "get logs of job") | ||
.option("-e, --end <end>", "End of logs") | ||
.action((async ({ jobId, options }) => { | ||
.action(utils_1.wrapTryCatch(async ({ jobId, options }) => { | ||
const queue = await queue_1.getQueue(); | ||
@@ -210,5 +200,3 @@ const { logs, count } = await queue.getJobLogs(jobId, options.start, options.end); | ||
})); | ||
exports.vorpal | ||
.command("log <jobId> <data>", "add log to job") | ||
.action(async function ({ jobId, data }) { | ||
exports.vorpal.command("log <jobId> <data>", "add log to job").action(utils_1.wrapTryCatch(async function ({ jobId, data }) { | ||
await queue_1.getQueue(); | ||
@@ -219,4 +207,4 @@ const job = await utils_1.getJob(jobId); | ||
utils_1.logGreen("Log added to job"); | ||
}); | ||
})); | ||
exports.vorpal.history("bull-repl-default"); | ||
exports.vorpal.delimiter("BULL-REPL> ").show(); |
{ | ||
"name": "bull-repl", | ||
"version": "0.16.1", | ||
"version": "0.16.2", | ||
"description": "Bull queue command line REPL", | ||
@@ -30,4 +30,4 @@ "repository": { | ||
"@types/ms": "0.7.31", | ||
"@types/node": "12.7.7", | ||
"@types/vorpal": "1.11.0", | ||
"@types/node": "12.7.8", | ||
"@types/vorpal": "1.12.0", | ||
"ts-node": "8.4.1", | ||
@@ -39,3 +39,3 @@ "type-coverage": "2.3.0", | ||
"build": "npx type-coverage --at-least 100 --ignore-catch; rm index.js; tsc --build tsconfig.json; gsed -i '1 i #!/usr/bin/env node' index.js; chmod +x index.js", | ||
"dev": "TS_NODE_TRANSPILE_ONLY=true TS_NODE_PREFER_TS_EXTS=true ts-node index.ts", | ||
"dev": "TS_NODE_TRANSPILE_ONLY=true TS_NODE_PREFER_TS_EXTS=true node --inspect -r ts-node/register index.ts", | ||
"test": "echo \"Error: no test specified\" && exit 1", | ||
@@ -42,0 +42,0 @@ "prepublish": "npm run build" |
@@ -88,2 +88,3 @@ "use strict"; | ||
let err = new Error(); | ||
err.yellow = true; | ||
err.stack = chalk_1.default.yellow(msg); | ||
@@ -111,1 +112,15 @@ throw err; | ||
exports.splitJobsByFound = splitJobsByFound; | ||
function wrapTryCatch(fn) { | ||
return async function (args) { | ||
try { | ||
return await fn.call(this, args); | ||
} | ||
catch (e) { | ||
if (e.yellow) { | ||
throw e; | ||
} | ||
return exports.throwYellow(e.message); | ||
} | ||
}; | ||
} | ||
exports.wrapTryCatch = wrapTryCatch; |
17465
4.08%337
0.9%