heartbeat.js
817 Bytes
var redis = require('redis');
var interval = 3600 * 1000;
var key_prefix = 'kamehame';
function beat(redis_client) {
var redis_key = key_prefix + '.gw:' + config.globals.gateway_name
var data = {
gateway_name: config.globals.gateway_name,
admin_port: config.globals.admin_port,
expresso_port: config.globals.expresso_port,
};
try {
var value = JSON.stringify(data)
redis_client.set(redis_key, value);
redis_client.expire(key, interval * 2);
redis_client.publish(redis_key, value);
}
catch (err) {
}
}
function start(config) {
var redis_client = redis.createClient(config.globals.redis_port, config.globals.redis_host);
beat(redis_client);
setInterval(beat, interval, redis_client);
}