Skip to content
Browse files

Executor command shows summary of both idle and active executors count.

  • Loading branch information...
1 parent c1bdc67 commit fca8a6550e549ba9c833a526878697af8779a2a5 @cliffano committed
Showing with 28 additions and 23 deletions.
  1. +2 −1 conf/locales/id.json
  2. +1 −4 lib/cli.js
  3. +1 −4 lib/irc.js
  4. +12 −2 lib/jenkins.js
  5. +4 −4 test/cli.js
  6. +6 −6 test/irc.js
  7. +2 −2 test/jenkins.js
View
3 conf/locales/id.json
@@ -31,6 +31,7 @@
"Usage: %s <command> <arg1> ... <argN>": "Penggunaan: %s <perintah> <arg1> ... <argN>",
"Username: ": "Nama pengguna: ",
"Queue is empty": "Antrean kosong",
- "(%d idle executor)": "(%d pelaksana diam)",
+ "%d active": "%d aktif",
+ "%d idle": "%d diam",
" stuck!": " macet!"
}
View
5 lib/cli.js
@@ -141,10 +141,7 @@ function _executor(args) {
jenkins.executor(cli.exitCb(null, function (result) {
if (!_.isEmpty(_.keys(result))) {
_.keys(result).forEach(function (computer) {
- console.log('+ %s %s', computer,
- (result[computer].idleCount > 0) ?
- text.__('(%d idle executor)', result[computer].idleCount) :
- '');
+ console.log('+ %s | %s', computer, result[computer].summary);
result[computer].executors.forEach(function (executor) {
if (!executor.idle) {
console.log(' - %s | %s%%s', executor.name, executor.progress, (executor.stuck) ? text.__(' stuck!') : '');
View
5 lib/irc.js
@@ -42,10 +42,7 @@ function _executor() {
jenkins.executor(bot.handleCb(function (result) {
if (!_.isEmpty(_.keys(result))) {
_.keys(result).forEach(function (computer) {
- bot.say('+ %s %s', computer,
- (result[computer].idleCount > 0) ?
- text.__('(%d idle executor)', result[computer].idleCount) :
- '');
+ bot.say('+ %s | %s', computer, result[computer].summary);
result[computer].executors.forEach(function (executor) {
if (!executor.idle) {
bot.say(' - %s | %s%%s', executor.name, executor.progress, (executor.stuck) ? ' stuck!' : '');
View
14 lib/jenkins.js
@@ -310,7 +310,8 @@ Jenkins.prototype.executor = function (cb) {
data = {};
computers.forEach(function (computer) {
data[computer.displayName] = { executors: [] };
- var idleCount = 0;
+ var idleCount = 0,
+ activeCount = 0;
computer.executors.forEach(function (executor) {
data[computer.displayName].executors.push({
idle: executor.idle,
@@ -322,9 +323,18 @@ Jenkins.prototype.executor = function (cb) {
});
if (executor.idle) {
idleCount += 1;
+ } else {
+ activeCount += 1;
}
});
- data[computer.displayName].idleCount = idleCount;
+ var summary = [];
+ if (activeCount > 0) {
+ summary.push(text.__('%d active', activeCount));
+ }
+ if (idleCount > 0) {
+ summary.push(text.__('%d idle', idleCount));
+ }
+ data[computer.displayName].summary = summary.join(', ');
});
cb(null, data);
}
View
8 test/cli.js
@@ -308,10 +308,10 @@ 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('+ %s %s', 'master', '(1 idle executor)');
+ this.mockConsole.expects('log').once().withExactArgs('+ %s | %s', 'master', '2 active, 1 idle');
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('+ %s %s', 'slave', '');
+ this.mockConsole.expects('log').once().withExactArgs('+ %s | %s', 'slave', '1 active');
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) {
@@ -322,13 +322,13 @@ buster.testCase('cli - executor', {
{ idle: false, name: 'job1', progress: 5 },
{ idle: false, progress: 33 }
],
- idleCount: 1
+ summary: '2 active, 1 idle'
},
slave: {
executors: [
{ idle: false, stuck: true, name: 'job2' , progress: 11 }
],
- idleCount: 0
+ summary: '1 active'
}
});
});
View
12 test/irc.js
@@ -212,22 +212,22 @@ buster.testCase('irc - executor', {
{ idle: false, name: 'job1', progress: 5 },
{ idle: false, progress: 33 }
],
- idleCount: 1
+ summary: '2 active, 1 idle'
},
slave: {
executors: [
{ idle: false, stuck: true, name: 'job2' , progress: 11 }
],
- idleCount: 0
+ summary: '1 active'
}
});
});
this.stub(Bot.prototype, 'say', function () {
result.push(arguments);
if (result.length === 5) {
- assert.equals(result[0][0], '+ %s %s');
+ assert.equals(result[0][0], '+ %s | %s');
assert.equals(result[0][1], 'master');
- assert.equals(result[0][2], '(1 idle executor)');
+ assert.equals(result[0][2], '2 active, 1 idle');
assert.equals(result[1][0], ' - %s | %s%%s');
assert.equals(result[1][1], 'job1');
assert.equals(result[1][2], 5);
@@ -236,9 +236,9 @@ buster.testCase('irc - executor', {
assert.equals(result[2][1], undefined);
assert.equals(result[2][2], 33);
assert.equals(result[2][3], '');
- assert.equals(result[3][0], '+ %s %s');
+ assert.equals(result[3][0], '+ %s | %s');
assert.equals(result[3][1], 'slave');
- assert.equals(result[3][2], '');
+ assert.equals(result[3][2], '1 active');
assert.equals(result[4][0], ' - %s | %s%%s');
assert.equals(result[4][1], 'job2');
assert.equals(result[4][2], 11);
View
4 test/jenkins.js
@@ -674,7 +674,7 @@ buster.testCase('jenkins - executor', {
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);
+ assert.equals(result.master.summary, '1 active, 1 idle');
// single executor on a slave
assert.equals(result.slave.executors.length, 1);
@@ -682,7 +682,7 @@ buster.testCase('jenkins - executor', {
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);
+ assert.equals(result.slave.summary, '1 active');
done();
});

0 comments on commit fca8a65

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