This commit is contained in:
panaceya 2024-10-21 09:20:26 +03:00 committed by GitHub
parent e57f315dcb
commit 2b1263ec4a
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 6 additions and 3 deletions

View file

@ -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)

View file

@ -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("""