From 24b5ea88a58b888fb0e4b598bb6f4303ac11d213 Mon Sep 17 00:00:00 2001
From: Nico Vermaas <vermaas@astron.nl>
Date: Tue, 8 Feb 2022 17:34:40 +0100
Subject: [PATCH] bonus: added a '(late)' timestamp in the monitor when a
 timestamp arrives > 60 seconds late.

---
 atdb/taskdatabase/services/algorithms.py | 10 +++++++++-
 1 file changed, 9 insertions(+), 1 deletion(-)

diff --git a/atdb/taskdatabase/services/algorithms.py b/atdb/taskdatabase/services/algorithms.py
index 3db3fa83..0e8bca9f 100644
--- a/atdb/taskdatabase/services/algorithms.py
+++ b/atdb/taskdatabase/services/algorithms.py
@@ -4,6 +4,7 @@
     Description:  Business logic for ATDB. These functions are called from the views (views.py).
 """
 
+from datetime import datetime, timedelta
 from django.db.models import Q, Sum
 import logging
 from .common import timeit
@@ -261,7 +262,14 @@ def convert_monitor_to_html(request, monitor_data):
             line += "<td><b>" + link_to_service_history + "</b></td>"
             line += "<td>" + str(record.hostname) + "</td>"
             line += '<td class="' + record.status + '" >' + str(record.status) + "</td>"
-            line += "<td>" + str(record.timestamp) + "</td>"
+
+            d1 = datetime.utcnow().replace(tzinfo=None)
+            d2 = record.timestamp.replace(tzinfo=None)
+            delta = d1 - d2
+            if delta.seconds > 60:
+                line += '<td class="error">' + str(record.timestamp.strftime(TIME_FORMAT)) + " - (late)</td>"
+            else:
+                line += '<td>' + str(record.timestamp) + "</td>"
             line += "<td>" + str(record.process_id) + "</td>"
             line += "<td>" + str(record.description) + "</td>"
             line += "</tr>"
-- 
GitLab