-
Notifications
You must be signed in to change notification settings - Fork 11
/
admin.js
69 lines (65 loc) · 2.86 KB
/
admin.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
"use strict";
var packet = require('gearman-packet');
var AbraxasError = require('./errors');
var ClientTask = require('./task-client');
exports.status = function (options,onComplete) {
if (options instanceof Function) { onComplete = options; options = null }
if (! options) options = {};
var responseTimeout = options.responseTimeout != null ? options.responseTimeout : this.options.responseTimeout;
var task = new ClientTask(onComplete);
if (responseTimeout) task.setResponseTimeout(responseTimeout);
task.beginPartial();
var status = {};
task.prepareResultWith(function(complete){ complete(status) });
this.getConnectedServers().forEach(function(conn) {
task.beginPartial();
conn.socket.adminTable('status', function (err,table) {
if (err) return;
table.forEach(function(line) {
if (! status[line.function]) return status[line.function] = line;
var match = status[line.function];
match.inqueue += line.inqueue;
match.running += line.running;
match.workers += line.workers;
});
task.endPartial();
}, function (result) {
var jobkind = result.args.line.split(/\t/);
return {function:jobkind[0], inqueue:jobkind[1]|0, running:jobkind[2]|0, workers:jobkind[3]|0};
});
});
return task.endPartial();
}
exports.workers = function (options,onComplete) {
if (options instanceof Function) { onComplete = options; options = null }
if (! options) options = {};
var responseTimeout = options.responseTimeout != null ? options.responseTimeout : this.options.responseTimeout;
var task = new ClientTask(onComplete);
if (responseTimeout) task.setResponseTimeout(responseTimeout);
task.beginPartial();
var workers = [];
task.prepareResultWith(function(complete){ complete(workers) });
this.getConnectedServers().forEach(function(conn) {
task.beginPartial();
conn.socket.adminTable('workers', function (err,table) {
if (err) return;
workers.push.apply(workers,table);
task.endPartial();
},
function (result) {
var matched = result.args.line.match(/^(\d+) (\S+) (\S+) :(?: (.+))?/);
if (! matched) return;
return {server:conn.newConnection.options,fd:matched[1], ip:matched[2], clientid:matched[3]=='-'?null:matched[3], functions:matched[4]?matched[4].split(/ /):[]};
});
});
return task.endPartial();
}
exports.shutdown = function (graceful,onComplete) {
var task = new ClientTask(onComplete);
task.beginPartial();
this.getConnectedServers().forEach(function(conn) {
task.beginPartial();
conn.socket.adminSingleResult('shutdown'+(graceful?' graceful':''), function (){ task.endPartial() });
});
return task.endPartial();
}