summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEvgeny Zinoviev <me@ch1p.io>2021-05-07 23:01:11 +0300
committerEvgeny Zinoviev <me@ch1p.io>2021-05-07 23:01:11 +0300
commit6589671f029d2db3bc110ca0098ed4509c698313 (patch)
tree012491fa275a21653d1f466962c65025c6d95fe8
parenta0a3ee5c2652cd1f1aacaacaae5f3a67293018d3 (diff)
jobd: support 'name' config option
-rw-r--r--README.md7
-rwxr-xr-xsrc/jobctl.js4
-rwxr-xr-xsrc/jobd-master.js8
-rwxr-xr-xsrc/jobd.js2
-rw-r--r--src/lib/config.js1
-rw-r--r--src/lib/workers-list.js10
6 files changed, 22 insertions, 10 deletions
diff --git a/README.md b/README.md
index acde972..046dd2b 100644
--- a/README.md
+++ b/README.md
@@ -61,7 +61,7 @@ time already, and proven to be stable and efficient.
- [remove-target(target: string)](#remove-targettarget-string)
- [set-target-concurrency(target: string, concurrency: int)](#set-target-concurrencytarget-string-concurrency-int)
- [jobd-master requests](#jobd-master-requests)
- - [register-worker(targets: string[])](#register-workertargets-string)
+ - [register-worker(targets: string[], name: string)](#register-workertargets-string-name-string)
- [poke(targets: string[])](#poketargets-string)
- [pause(targets: string[])](#pausetargets-string-1)
- [continue(targets: string[])](#continuetargets-string-1)
@@ -411,6 +411,7 @@ Without section:
- `always_allow_localhost` *(boolean, default: `false`)* — when set to `1`
or `true`, allows accepting requests from clients connecting from localhost
without password
+- `name` *(string, default: `os.hostname()`)* — worker name
- `master_host` *(string)* — master hostname
- `master_port` *(int)* — master port. If hostname or port is omitted, jobd
will not connect to master.
@@ -608,8 +609,8 @@ Here is the list of supported requests, using `type(arguments)` notation.
#### jobd-master requests
-* ##### `register-worker(targets: string[])`
- Used by a jobd instance to register itself with master. Clients don't need it.
+* ##### `register-worker(targets: string[], name: string)`
+ Used by jobd instances to register themselves with master. Clients don't need it.
* ##### `poke(targets: string[])`
Send [`poll(targets)`](#polltargets-string) requests to all registered workers that serve specified
diff --git a/src/jobctl.js b/src/jobctl.js
index 887a073..05e91c8 100755
--- a/src/jobctl.js
+++ b/src/jobctl.js
@@ -267,13 +267,13 @@ async function masterListWorkers() {
const columns = ['worker', 'targets', 'concurrency', 'length', 'paused']
const rows = []
for (const worker of response.workers) {
- let remoteAddr = `${worker.remoteAddr}:${worker.remotePort}`
+ let info = `${worker.name}\n(${worker.remoteAddr})`
let targets = Object.keys(worker.workerStatus.targets)
let concurrencies = targets.map(t => worker.workerStatus.targets[t].concurrency)
let lengths = targets.map(t => worker.workerStatus.targets[t].length)
let pauses = targets.map(t => worker.workerStatus.targets[t].paused ? 'yes' : 'no')
rows.push([
- remoteAddr,
+ info,
targets.join("\n"),
concurrencies.join("\n"),
lengths.join("\n"),
diff --git a/src/jobd-master.js b/src/jobd-master.js
index eeac085..34e03ba 100755
--- a/src/jobd-master.js
+++ b/src/jobd-master.js
@@ -149,7 +149,13 @@ async function term() {
*/
async function onRegisterWorker(data, connection) {
const targets = validateInputTargets(data, null)
- workers.add(connection, targets)
+ if (typeof data.name !== 'string')
+ throw new Error('name is missing or invalid')
+
+ workers.add(connection, {
+ targets,
+ name: data.name
+ })
return 'ok'
}
diff --git a/src/jobd.js b/src/jobd.js
index b5d605f..7c63607 100755
--- a/src/jobd.js
+++ b/src/jobd.js
@@ -1,5 +1,6 @@
#!/usr/bin/env node
const minimist = require('minimist')
+const os = require('os')
const loggerModule = require('./lib/logger')
const config = require('./lib/config')
const db = require('./lib/db')
@@ -183,6 +184,7 @@ function connectToMaster() {
try {
let response = await connection.sendRequest(
new RequestMessage('register-worker', {
+ name: config.get('name') || os.hostname(),
targets: worker.getTargets()
})
)
diff --git a/src/lib/config.js b/src/lib/config.js
index f3a9e61..4228621 100644
--- a/src/lib/config.js
+++ b/src/lib/config.js
@@ -71,6 +71,7 @@ function parseWorkerConfig(file) {
const raw = readFile(file)
const scheme = {
+ name: {},
host: {required: true},
port: {required: true, type: 'int'},
password: {},
diff --git a/src/lib/workers-list.js b/src/lib/workers-list.js
index 3f2246e..c779ec2 100644
--- a/src/lib/workers-list.js
+++ b/src/lib/workers-list.js
@@ -35,11 +35,12 @@ class WorkersList {
/**
* @param {Connection} connection
* @param {string[]} targets
+ * @param {string} name
*/
- add(connection, targets) {
- this.logger.info(`add: connection from ${connection.remoteAddr()}, targets ${JSON.stringify(targets)}`)
+ add(connection, {targets, name}) {
+ this.logger.info(`add: connection from ${connection.remoteAddr()}, name ${name}, targets ${JSON.stringify(targets)}`)
- this.workers.push({connection, targets})
+ this.workers.push({connection, targets, name})
connection.on('close', () => {
this.logger.info(`connection from ${connection.remoteAddr()} closed, removing worker`)
this.workers = this.workers.filter(worker => {
@@ -161,7 +162,8 @@ class WorkersList {
const workerInfo = {
remoteAddr: worker.connection.socket?.remoteAddress,
remotePort: worker.connection.socket?.remotePort,
- targets: worker.targets
+ targets: worker.targets,
+ name: worker.name,
}
if (pollWorkers) {