diff --git a/monitoring/db_update_sqlite.py b/monitoring/db_update_sqlite.py index 7548c2c..bf90547 100644 --- a/monitoring/db_update_sqlite.py +++ b/monitoring/db_update_sqlite.py @@ -492,11 +492,16 @@ def refresh_gridsitesync_submithost(): site = record.get("Site") month = record.get("Month") year = record.get("Year") - submit_host = record.get("SubmitHostSumm") or record.get("SubmitHostSync") - record_start = record.get("RecordStart") + # Use SubmitHostSync when SubmitHostSumm is missing (NaN) + submit_host = ( + record.get("SubmitHostSync") + if pd.isna(record.get("SubmitHostSumm")) + else record.get("SubmitHostSumm") + ) + record_start = none_if_missing(record.get("RecordStart")) + record_end = none_if_missing(record.get("RecordEnd")) - # Skip rows where RecordStart is missing or NaN - if pd.isna(record_start): + if pd.isna(submit_host): continue # Sanitize numeric fields @@ -516,7 +521,7 @@ def refresh_gridsitesync_submithost(): SubmitHost=submit_host, defaults={ 'RecordStart': record_start, - 'RecordEnd': record.get("RecordEnd"), + 'RecordEnd': record_end, 'RecordCountPublished': record_count_published, 'RecordCountInDb': record_count_in_db, } @@ -528,6 +533,13 @@ def refresh_gridsitesync_submithost(): log.exception("Error while trying to refresh GridSiteSyncSubmitH") +def none_if_missing(value): + """ + Return None when the value is missing (NaN/NaT), otherwise return it unchanged. + """ + return None if pd.isna(value) else value + + if __name__ == "__main__": log.info('=====================') diff --git a/monitoring/publishing/models.py b/monitoring/publishing/models.py index 195872d..27de057 100644 --- a/monitoring/publishing/models.py +++ b/monitoring/publishing/models.py @@ -86,8 +86,8 @@ class GridSiteSyncSubmitH(models.Model): YearMonth = models.CharField(max_length=255) Year = models.IntegerField() Month = models.IntegerField() - RecordStart = models.DateTimeField() - RecordEnd = models.DateTimeField() + RecordStart = models.DateTimeField(null=True) + RecordEnd = models.DateTimeField(null=True) RecordCountPublished = models.IntegerField() RecordCountInDb = models.IntegerField() SubmitHost = models.CharField(max_length=255) diff --git a/monitoring/publishing/templates/gridsync_submithost.html b/monitoring/publishing/templates/gridsync_submithost.html index 0baf9aa..d43d0f3 100644 --- a/monitoring/publishing/templates/gridsync_submithost.html +++ b/monitoring/publishing/templates/gridsync_submithost.html @@ -35,8 +35,8 @@