Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New cancel-failures, cancel-queue, run subcommands #59

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
79 changes: 77 additions & 2 deletions bin/qless-js.js
Original file line number Diff line number Diff line change
Expand Up @@ -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));
};

/**
Expand Down Expand Up @@ -212,6 +212,66 @@ 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;
}
}
});
};

/**
* 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);
}
}
});
};

/**
* 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 <url>', 'The redis:// url to connect to')
.option('-v, --verbose', 'Increase logging level', logger.increaseVerbosity);
Expand Down Expand Up @@ -316,4 +376,19 @@ 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
.command('cancel-queue [queues...]')
.description('Cancel all jobs in the provided queue')
.action(cancelQueue);

commander
.command('run <jid>')
.description('Run the provided job (useful for debugging)')
.action(run);

commander.parse(process.argv);
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "qless-js",
"version": "0.4.9",
"version": "0.4.10",
"private": false,
"description": "Qless JavaScript Bindings",
"main": "index.js",
Expand Down