-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathclient.js
executable file
·62 lines (55 loc) · 1.77 KB
/
client.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
#!/usr/bin/env node
var util = require('util')
, ThalassaClient = require('..')
, optimist = require('optimist')
.options({
host: {
default : '127.0.0.1',
describe: 'thalassa host'
},
apiport: {
default : 9000,
describe: 'thalassa http api port'
},
register: {
describe: 'name@x.x.x:port,name@x.x.x:port'
},
secsToExpire: {
default : 60,
describe: 'default time in seconds for a thalassa registration to be valid'
},
updateFreq: {
default : 20000,
describe: 'time frequency in ms to ping the thalassa server'
},
updateTimeout: {
default : 2500,
describe: 'time in ms to wait for a registrion request to respond'
},
debug: {
boolean: true,
describe: 'enabled debug logging'
},
showhelp: {
alias: 'h'
}
})
.demand('register');
var argv = optimist.argv;
if (argv.h) {
optimist.showHelp();
process.exit(0);
}
var log = argv.log = require('../lib/defaultLogger')( (argv.debug == true) ? 'debug' : 'error' );
var client = new ThalassaClient(argv);
// TODO validate format of `register` option
argv.register.split(',').forEach(function (nvp) {
var parts = nvp.split('@');
var name = parts[0];
parts = parts[1].split(':');
var version = parts[0];
var port = parts[1];
client.register(name, version, port);
log('info', util.format('registering %s@%s on port %s', name, version, port));
})
client.start();