From 2b1263ec4a8daca8a6d81624c9fa629b0fd0d219 Mon Sep 17 00:00:00 2001 From: panaceya Date: Mon, 21 Oct 2024 09:20:26 +0300 Subject: [PATCH] FIX: #60 --- exporter/metric/node_metrics.py | 5 +++-- exporter/processor/processors.py | 4 +++- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/exporter/metric/node_metrics.py b/exporter/metric/node_metrics.py index 7a5c9f0..1b70b09 100644 --- a/exporter/metric/node_metrics.py +++ b/exporter/metric/node_metrics.py @@ -1,3 +1,4 @@ +from datetime import datetime from prometheus_client import CollectorRegistry, Counter, Gauge from exporter.client_details import ClientDetails @@ -48,9 +49,9 @@ class Metrics: def db_operation(cur, conn): cur.execute(""" UPDATE node_details - SET latitude = %s, longitude = %s, altitude = %s, precision = %s + SET latitude = %s, longitude = %s, altitude = %s, precision = %s, updated_at = %s WHERE node_id = %s - """, (latitude, longitude, altitude, precision, client_details.node_id)) + """, (latitude, longitude, altitude, precision, datetime.now().isoformat(), client_details.node_id)) conn.commit() self.db.execute_db_operation(db_operation) diff --git a/exporter/processor/processors.py b/exporter/processor/processors.py index bb2c7bf..e8b0aa8 100644 --- a/exporter/processor/processors.py +++ b/exporter/processor/processors.py @@ -1,5 +1,6 @@ import os from abc import ABC, abstractmethod +from datetime import datetime from venv import logger import psycopg @@ -151,12 +152,13 @@ class NodeInfoAppProcessor(Processor): update_values.append(ClientDetails.get_role_name_from_role(user.role)) if update_fields: + update_fields.append("updated_at = %s") update_query = f""" UPDATE node_details SET {", ".join(update_fields)} WHERE node_id = %s """ - cur.execute(update_query, update_values + [client_details.node_id]) + cur.execute(update_query, update_values + [datetime.now().isoformat(), client_details.node_id]) else: # If record doesn't exist, insert a new one cur.execute("""