From 29a1cc31cf68f92c9e4dab48e1762a0ad39e81c3 Mon Sep 17 00:00:00 2001 From: Falkvinge Date: Wed, 22 Mar 2017 17:53:25 +0100 Subject: [PATCH] Added internal heartbeats from backend --- Backend/BackendLoop.cs | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/Backend/BackendLoop.cs b/Backend/BackendLoop.cs index eaec50f7..f97b875b 100644 --- a/Backend/BackendLoop.cs +++ b/Backend/BackendLoop.cs @@ -293,6 +293,7 @@ namespace Swarmops.Backend // Wait for a maximum of ten seconds (the difference between cycleStartTime and cycleEndTime) + int iterationCount = 0; DateTime utcNow = DateTime.UtcNow; while (utcNow < cycleEndTime && !exitFlag) { @@ -327,6 +328,13 @@ namespace Swarmops.Backend } utcNow = DateTime.UtcNow; + + // Every second, send an internal heartbeat + + if (iterationCount++%4 == 0) + { + InternalHeartbeat(); + } } } } @@ -840,6 +848,15 @@ namespace Swarmops.Backend } } + private static void InternalHeartbeat() + { + JObject json = new JObject(); + json["MessageType"] = "InternalHeartbeat"; + json["Timestamp"] = DateTime.UtcNow.ToUnix(); + + _socketServer.WebSocketServices.Broadcast(json.ToString()); + } + private static void BroadcastTimestamp() { JObject json = new JObject();