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 ...@@ -101,7 +101,7 @@ function startWorker(local_repository, functionHash,function_id, producer, runti
function heartbeat() { function heartbeat() {
let payload = [{ let payload = [{
topic: "heartbeat", topic: "heartbeat",
messages: JSON.stringify({"address": node_id}) messages: JSON.stringify({"address": node_id, "timestamp": Date.now()})
}] }]
producer.send(payload, function() { producer.send(payload, function() {
......
...@@ -222,7 +222,7 @@ consumer.on('message', function (message) { ...@@ -222,7 +222,7 @@ consumer.on('message', function (message) {
db.delete(message.function_id) db.delete(message.function_id)
} else if (topic === "heartbeat") { } else if (topic === "heartbeat") {
message = JSON.parse(message) message = JSON.parse(message)
if (Date.now() - message.timestamp < 300)
if (workerNodes.indexOf(message.address) === -1) { if (workerNodes.indexOf(message.address) === -1) {
workerNodes.push(message.address) workerNodes.push(message.address)
console.log(workerNodes); 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