Skip to content
Browse files

Executor command collapses idle executors list into a summary. #22

  • Loading branch information...
1 parent 40858ca commit c1ddd217d461bbba366eb188b5a8fa73f26d2539 @cliffano committed
Showing with 84 additions and 60 deletions.
  1. +1 −0 CHANGELOG.md
  2. +1 −1 conf/locales/id.json
  3. +6 −5 lib/cli.js
  4. +6 −5 lib/irc.js
  5. +7 −2 lib/jenkins.js
  6. +16 −11 test/cli.js
  7. +31 −22 test/irc.js
  8. +16 −14 test/jenkins.js
View
1 CHANGELOG.md
@@ -1,5 +1,6 @@
### 0.2.0
* Add l10n support, with en and id locales
+* Executor command collapses idle executors list into a summary
### 0.1.10
* Add discover command timeout after 5 seconds
View
2 conf/locales/id.json
@@ -31,6 +31,6 @@
"Usage: %s <command> <arg1> ... <argN>": "Cara penggunaan: %s <perintah> <arg1> ... <argN>",
"Username: ": "Pengguna: ",
"Queue is empty": "Antrean kosong",
- "idle": "diam",
+ "(%d idle executor)": "(%d eksekutor diam)",
" stuck!": " berhenti!"
}
View
11 lib/cli.js
@@ -141,11 +141,12 @@ function _executor(args) {
jenkins.executor(cli.exitCb(null, function (result) {
if (!_.isEmpty(_.keys(result))) {
_.keys(result).forEach(function (computer) {
- console.log('+ ' + computer);
- result[computer].forEach(function (executor) {
- if (executor.idle) {
- console.log(' - ' + text.__('idle'));
- } else {
+ console.log('+ %s %s', computer,
+ (result[computer].idleCount > 0) ?
+ text.__('(%d idle executor)', result[computer].idleCount) :
+ '');
+ result[computer].executors.forEach(function (executor) {
+ if (!executor.idle) {
console.log(' - %s | %s%%s', executor.name, executor.progress, (executor.stuck) ? text.__(' stuck!') : '');
}
});
View
11 lib/irc.js
@@ -42,11 +42,12 @@ function _executor() {
jenkins.executor(bot.handleCb(function (result) {
if (!_.isEmpty(_.keys(result))) {
_.keys(result).forEach(function (computer) {
- bot.say('+ ' + computer);
- result[computer].forEach(function (executor) {
- if (executor.idle) {
- bot.say(' - ' + text.__('idle'));
- } else {
+ bot.say('+ %s %s', computer,
+ (result[computer].idleCount > 0) ?
+ text.__('(%d idle executor)', result[computer].idleCount) :
+ '');
+ result[computer].executors.forEach(function (executor) {
+ if (!executor.idle) {
bot.say(' - %s | %s%%s', executor.name, executor.progress, (executor.stuck) ? ' stuck!' : '');
}
});
View
9 lib/jenkins.js
@@ -309,9 +309,10 @@ Jenkins.prototype.executor = function (cb) {
var computers = JSON.parse(result.body).computer,
data = {};
computers.forEach(function (computer) {
- data[computer.displayName] = [];
+ data[computer.displayName] = { executors: [] };
+ var idleCount = 0;
computer.executors.forEach(function (executor) {
- data[computer.displayName].push({
+ data[computer.displayName].executors.push({
idle: executor.idle,
stuck: executor.likelyStuck,
progress: executor.progress,
@@ -319,7 +320,11 @@ Jenkins.prototype.executor = function (cb) {
executor.currentExecutable.url.replace(/.*\/job\//, '').replace(/\/.*/, '') :
undefined
});
+ if (executor.idle) {
+ idleCount += 1;
+ }
});
+ data[computer.displayName].idleCount = idleCount;
});
cb(null, data);
}
View
27 test/cli.js
@@ -308,23 +308,28 @@ buster.testCase('cli - executor', {
});
},
'should log executor status when exec executor is called and there are some executors': function () {
- this.mockConsole.expects('log').once().withExactArgs('+ master');
- this.mockConsole.expects('log').once().withExactArgs(' - idle');
+ this.mockConsole.expects('log').once().withExactArgs('+ %s %s', 'master', '(1 idle executor)');
this.mockConsole.expects('log').once().withExactArgs(' - %s | %s%%s', 'job1', 5, '');
this.mockConsole.expects('log').once().withExactArgs(' - %s | %s%%s', undefined, 33, '');
- this.mockConsole.expects('log').once().withExactArgs('+ slave');
+ this.mockConsole.expects('log').once().withExactArgs('+ %s %s', 'slave', '');
this.mockConsole.expects('log').once().withExactArgs(' - %s | %s%%s', 'job2', 11, ' stuck!');
this.mockProcess.expects('exit').once().withExactArgs(0);
this.stub(Jenkins.prototype, 'executor', function (cb) {
cb(null, {
- master: [
- { idle: true },
- { idle: false, name: 'job1', progress: 5 },
- { idle: false, progress: 33 }
- ],
- slave: [
- { idle: false, stuck: true, name: 'job2' , progress: 11 }
- ]
+ master: {
+ executors: [
+ { idle: true },
+ { idle: false, name: 'job1', progress: 5 },
+ { idle: false, progress: 33 }
+ ],
+ idleCount: 1
+ },
+ slave: {
+ executors: [
+ { idle: false, stuck: true, name: 'job2' , progress: 11 }
+ ],
+ idleCount: 0
+ }
});
});
cli.exec();
View
53 test/irc.js
@@ -206,34 +206,43 @@ buster.testCase('irc - executor', {
var result = [];
this.stub(Jenkins.prototype, 'executor', function (cb) {
cb(null, {
- master: [
- { idle: true },
- { idle: false, name: 'job1', progress: 5 },
- { idle: false, progress: 33 }
- ],
- slave: [
- { idle: false, stuck: true, name: 'job2' , progress: 11 }
- ]
+ master: {
+ executors: [
+ { idle: true },
+ { idle: false, name: 'job1', progress: 5 },
+ { idle: false, progress: 33 }
+ ],
+ idleCount: 1
+ },
+ slave: {
+ executors: [
+ { idle: false, stuck: true, name: 'job2' , progress: 11 }
+ ],
+ idleCount: 0
+ }
});
});
this.stub(Bot.prototype, 'say', function () {
result.push(arguments);
- if (result.length === 6) {
- assert.equals(result[0][0], '+ master');
- assert.equals(result[1][0], ' - idle');
+ if (result.length === 5) {
+ assert.equals(result[0][0], '+ %s %s');
+ assert.equals(result[0][1], 'master');
+ assert.equals(result[0][2], '(1 idle executor)');
+ assert.equals(result[1][0], ' - %s | %s%%s');
+ assert.equals(result[1][1], 'job1');
+ assert.equals(result[1][2], 5);
+ assert.equals(result[1][3], '');
assert.equals(result[2][0], ' - %s | %s%%s');
- assert.equals(result[2][1], 'job1');
- assert.equals(result[2][2], 5);
+ assert.equals(result[2][1], undefined);
+ assert.equals(result[2][2], 33);
assert.equals(result[2][3], '');
- assert.equals(result[3][0], ' - %s | %s%%s');
- assert.equals(result[3][1], undefined);
- assert.equals(result[3][2], 33);
- assert.equals(result[3][3], '');
- assert.equals(result[4][0], '+ slave');
- assert.equals(result[5][0], ' - %s | %s%%s');
- assert.equals(result[5][1], 'job2');
- assert.equals(result[5][2], 11);
- assert.equals(result[5][3], ' stuck!');
+ assert.equals(result[3][0], '+ %s %s');
+ assert.equals(result[3][1], 'slave');
+ assert.equals(result[3][2], '');
+ assert.equals(result[4][0], ' - %s | %s%%s');
+ assert.equals(result[4][1], 'job2');
+ assert.equals(result[4][2], 11);
+ assert.equals(result[4][3], ' stuck!');
done();
}
});
View
30 test/jenkins.js
@@ -665,22 +665,24 @@ buster.testCase('jenkins - executor', {
assert.isNull(err);
// multiple executors on a master
- assert.equals(result.master.length, 2);
- assert.equals(result.master[0].progress, 88);
- assert.equals(result.master[0].stuck, false);
- assert.equals(result.master[0].idle, false);
- assert.equals(result.master[0].name, 'job1');
- assert.equals(result.master[1].progress, 0);
- assert.equals(result.master[1].stuck, false);
- assert.equals(result.master[1].idle, true);
- assert.equals(result.master[1].name, undefined);
+ assert.equals(result.master.executors.length, 2);
+ assert.equals(result.master.executors[0].progress, 88);
+ assert.equals(result.master.executors[0].stuck, false);
+ assert.equals(result.master.executors[0].idle, false);
+ assert.equals(result.master.executors[0].name, 'job1');
+ assert.equals(result.master.executors[1].progress, 0);
+ assert.equals(result.master.executors[1].stuck, false);
+ assert.equals(result.master.executors[1].idle, true);
+ assert.equals(result.master.executors[1].name, undefined);
+ assert.equals(result.master.idleCount, 1);
// single executor on a slave
- assert.equals(result.slave.length, 1);
- assert.equals(result.slave[0].progress, 88);
- assert.equals(result.slave[0].stuck, true);
- assert.equals(result.slave[0].idle, false);
- assert.equals(result.slave[0].name, 'job2');
+ assert.equals(result.slave.executors.length, 1);
+ assert.equals(result.slave.executors[0].progress, 88);
+ assert.equals(result.slave.executors[0].stuck, true);
+ assert.equals(result.slave.executors[0].idle, false);
+ assert.equals(result.slave.executors[0].name, 'job2');
+ assert.equals(result.slave.idleCount, 0);
done();
});

0 comments on commit c1ddd21

Please sign in to comment.
Something went wrong with that request. Please try again.