diff --git a/monitoring/db_update_sqlite.py b/monitoring/db_update_sqlite.py index fb85937..9fe2c1d 100644 --- a/monitoring/db_update_sqlite.py +++ b/monitoring/db_update_sqlite.py @@ -12,6 +12,7 @@ from django.db import DatabaseError import pandas as pd from django.utils.timezone import make_aware, is_naive +from datetime import datetime BASE_DIR = os.path.abspath(os.path.join(os.path.dirname(__file__), '..')) @@ -138,15 +139,34 @@ def determine_sync_status(f): """ Helper to determine sync status between published and the database record counts. """ + if is_current_month(f): + return "OK [ Current month ]" + RecordCountPublished = f.get("RecordCountPublished") RecordCountInDb = f.get("RecordCountInDb") - rel_diff1 = abs(RecordCountPublished - RecordCountInDb)/RecordCountInDb - rel_diff2 = abs(RecordCountPublished - RecordCountInDb)/RecordCountPublished - if rel_diff1 < 0.01 or rel_diff2 < 0.01: - syncstatus = "OK" - else: - syncstatus = "ERROR [ Please use the Gap Publisher to synchronise this dataset]" - return syncstatus + + # catches None or zero + if not RecordCountPublished or not RecordCountInDb: + return "WARNING [ Invalid record counts ]" + + diff = abs(RecordCountPublished - RecordCountInDb) + rel_diff1 = diff/RecordCountInDb + rel_diff2 = diff/RecordCountPublished + if RecordCountPublished > RecordCountInDb or rel_diff1 < 0.01 or rel_diff2 < 0.01: + return "OK" + + return "WARNING [ Please try to republish the missing data or raise a GGUS ticket ]" + + +def is_current_month(f): + month = f.get("Month") + year = f.get("Year") + + if month is None or year is None: + return False + + now = datetime.now() + return now.month == month and now.year == year def refresh_gridsite(): diff --git a/monitoring/publishing/templates/gridsync.html b/monitoring/publishing/templates/gridsync.html index ddda536..2fe03c6 100644 --- a/monitoring/publishing/templates/gridsync.html +++ b/monitoring/publishing/templates/gridsync.html @@ -38,8 +38,8 @@

APEL Synchronisation Test

{{ record.YearMonth }} {{ record.RecordStart }} {{ record.RecordEnd }} - {{ record.RecordCountPublished|intcomma }} {{ record.RecordCountInDb|intcomma }} + {{ record.RecordCountPublished|intcomma }} {{ record.SyncStatus }} {% endfor %} diff --git a/monitoring/publishing/templates/gridsync_singlesite.html b/monitoring/publishing/templates/gridsync_singlesite.html index 11a1cb2..7196be6 100644 --- a/monitoring/publishing/templates/gridsync_singlesite.html +++ b/monitoring/publishing/templates/gridsync_singlesite.html @@ -38,8 +38,8 @@

APEL Synchronisation Test

{{ record.RecordStart }} {{ record.RecordEnd }} - {{ record.RecordCountPublished|intcomma }} {{ record.RecordCountInDb|intcomma }} + {{ record.RecordCountPublished|intcomma }} {{ record.SyncStatus }} {% endfor %} diff --git a/monitoring/publishing/templates/gridsync_submithost.html b/monitoring/publishing/templates/gridsync_submithost.html index fdf2b47..0baf9aa 100644 --- a/monitoring/publishing/templates/gridsync_submithost.html +++ b/monitoring/publishing/templates/gridsync_submithost.html @@ -37,8 +37,8 @@

APEL Synchronisation Test

{{ host.SubmitHost }} {{ host.RecordStart }} {{ host.RecordEnd }} - {{ host.RecordCountPublished|intcomma }} {{ host.RecordCountInDb|intcomma }} + {{ host.RecordCountPublished|intcomma }} {% endfor %}