Commit 91956eb4 authored by Nilanjan Daw's avatar Nilanjan Daw

Timestamped Heartbeat

Added timestamp support to heartbeat for removing stale messages
parent 9d97bdfa
......@@ -101,7 +101,7 @@ function startWorker(local_repository, functionHash,function_id, producer, runti
function heartbeat() {
let payload = [{
topic: "heartbeat",
messages: JSON.stringify({"address": node_id})
messages: JSON.stringify({"address": node_id, "timestamp": Date.now()})
}]
producer.send(payload, function() {
......
......@@ -222,11 +222,11 @@ consumer.on('message', function (message) {
db.delete(message.function_id)
} else if (topic === "heartbeat") {
message = JSON.parse(message)
if (workerNodes.indexOf(message.address) === -1) {
workerNodes.push(message.address)
console.log(workerNodes);
}
if (Date.now() - message.timestamp < 300)
if (workerNodes.indexOf(message.address) === -1) {
workerNodes.push(message.address)
console.log(workerNodes);
}
}
});
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment