-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
49 lines (40 loc) · 1.19 KB
/
app.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
var os = require('os'),
net = require('net');
function getConfig() {
return {
interval: parseInt(process.env.PERIODIC_INTERVAL || 60) * 1000,
port: parseInt(process.env.PORT || 0),
}
}
console.log('node-worker starting up.');
console.log('- Process Environment:');
console.dir(process.env);
process.on('exit', function (code) {
console.log('node-worker exiting (with code ' + code + ').');
});
var config = getConfig();
//
// Listen for health check if necessary
//
if (config.port) {
var server = new net.createServer(function (c) {
console.log('Received health check: "' + c.read() + '".');
c.write('hello\r\n');
c.end();
process.nextTick(function() { server.close(); });
});
server.listen(config.port);
}
//
// Run a periodic task
//
setInterval(function() {
var pid = process.pid,
uptime = process.uptime(),
hostname = os.hostname(),
time = new Date();
console.log('node-worker running periodic task at ' + time.toTimeString());
console.log(' - Process ID: ' + pid);
console.log(' - Uptime: ' + uptime + ' seconds');
console.log(' - DEA Hostname: ' + hostname);
}, config.interval);