From 099cdc288de1c069e32456878ade9d216f8ae58d Mon Sep 17 00:00:00 2001 From: Dan Lecocq Date: Thu, 4 Feb 2021 11:44:12 -0700 Subject: [PATCH 1/5] Add cancel-failures CLI helper --- bin/qless-js.js | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/bin/qless-js.js b/bin/qless-js.js index 7e54344..d29e19a 100755 --- a/bin/qless-js.js +++ b/bin/qless-js.js @@ -212,6 +212,25 @@ const config = (path, options) => { }); }; +/** + * Cancel all the jobs with the provided failures + */ +const cancelFailed = (types, options) => { + return logWithClient(options.parent, async (client) => { + for (const type of types) { + // eslint-disable-next-line no-await-in-loop + let jids = (await client.jobs.failed(type, 0, 1000)).jobs; + while (jids.length > 0) { + console.log(`Canceling ${jids.length} jobs`); + // eslint-disable-next-line no-await-in-loop + await client.cancel(...jids); + // eslint-disable-next-line no-await-in-loop + jids = (await client.jobs.failed(type, 0, 1000)).jobs; + } + } + }); +}; + commander .option('-r, --redis ', 'The redis:// url to connect to') .option('-v, --verbose', 'Increase logging level', logger.increaseVerbosity); @@ -316,4 +335,9 @@ commander .description('Display the config, or set the config from the provided path') .action(config); +commander + .command('cancel-failed [types...]') + .description('Cancel all jobs of the provided failure types') + .action(cancelFailed); + commander.parse(process.argv); From b78944c9fe8eeaabbb5b71f70577abd12b0cf0c5 Mon Sep 17 00:00:00 2001 From: Dan Lecocq Date: Thu, 4 Feb 2021 11:56:03 -0700 Subject: [PATCH 2/5] Add cancel-queue CLI helper --- bin/qless-js.js | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/bin/qless-js.js b/bin/qless-js.js index d29e19a..7bb64ba 100755 --- a/bin/qless-js.js +++ b/bin/qless-js.js @@ -231,6 +231,26 @@ const cancelFailed = (types, options) => { }); }; +/** + * Cancel all the jobs in the provided queue + */ +const cancelQueue = (queues, options) => { + return logWithClient(options.parent, async (client) => { + for (const name of queues) { + // eslint-disable-next-line no-await-in-loop + let jobs = await client.queue(name).peek(1000); + while (jobs.length > 0) { + console.log(`Canceling ${jobs.length} jobs`); + const jids = jobs.map(j => j.jid); + // eslint-disable-next-line no-await-in-loop + await client.cancel(...jids); + // eslint-disable-next-line no-await-in-loop + jobs = await client.queue(name).peek(1000); + } + } + }); +}; + commander .option('-r, --redis ', 'The redis:// url to connect to') .option('-v, --verbose', 'Increase logging level', logger.increaseVerbosity); @@ -340,4 +360,9 @@ commander .description('Cancel all jobs of the provided failure types') .action(cancelFailed); +commander + .command('cancel-queue [queues...]') + .description('Cancel all jobs in the provided queue') + .action(cancelQueue); + commander.parse(process.argv); From 7dbe3cf4d42846721d4b05972af1627e6147c1f6 Mon Sep 17 00:00:00 2001 From: Dan Lecocq Date: Tue, 16 Feb 2021 11:33:44 -0700 Subject: [PATCH 3/5] Add run subcommand --- bin/qless-js.js | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/bin/qless-js.js b/bin/qless-js.js index 7bb64ba..8765842 100755 --- a/bin/qless-js.js +++ b/bin/qless-js.js @@ -251,6 +251,27 @@ const cancelQueue = (queues, options) => { }); }; +/** + * Process a specific job (though calls to `complete` and `fail` will be mocked + * out). This is useful for debugging to see what a specific job's execution + * would be like. + */ +const run = (jid, options) => { + const util = require('util'); + return logWithClient(options.parent, async (client) => { + const found = await client.job(jid); + found.heartbeatUntilPromise = (promise) => promise; + found.complete = (...arguments) => { + console.log(`Called complete(${arguments.map(util.inspect).join(', ')})`); + }; + found.fail = (...arguments) => { + console.log(`Called fail(${arguments.map(util.inspect).join(', ')})`); + }; + + return found.process(); + }); +}; + commander .option('-r, --redis ', 'The redis:// url to connect to') .option('-v, --verbose', 'Increase logging level', logger.increaseVerbosity); @@ -365,4 +386,9 @@ commander .description('Cancel all jobs in the provided queue') .action(cancelQueue); +commander + .command('run ') + .description('Run the provided job (useful for debugging)') + .action(run); + commander.parse(process.argv); From fb98bb8f1324a0cd3271525726112b9dd6e3950e Mon Sep 17 00:00:00 2001 From: Dan Lecocq Date: Fri, 19 Mar 2021 07:50:50 -0600 Subject: [PATCH 4/5] Fix unrecur command --- bin/qless-js.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/bin/qless-js.js b/bin/qless-js.js index 8765842..78e138c 100755 --- a/bin/qless-js.js +++ b/bin/qless-js.js @@ -139,8 +139,8 @@ const cancel = (jids, options) => { /** * Unrecur one recurring jobs */ -const unrecur = (jid) => { - logWithClient(client => client.call('unrecur', jid)); +const unrecur = (jid, options) => { + logWithClient(options.parent, client => client.call('unrecur', jid)); }; /** From 64e641812b8233a2b4e330de75f4eca768ccda54 Mon Sep 17 00:00:00 2001 From: Dan Lecocq Date: Fri, 19 Mar 2021 07:51:39 -0600 Subject: [PATCH 5/5] Version bump to 0.4.10 --- package-lock.json | 2 +- package.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/package-lock.json b/package-lock.json index fce410a..0d02f33 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "qless-js", - "version": "0.4.9", + "version": "0.4.10", "lockfileVersion": 1, "requires": true, "dependencies": { diff --git a/package.json b/package.json index e8ad064..054c525 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "qless-js", - "version": "0.4.9", + "version": "0.4.10", "private": false, "description": "Qless JavaScript Bindings", "main": "index.js",