From 64780cab506dfa91119882a0466d3d69ebb3e794 Mon Sep 17 00:00:00 2001 From: Bryan Hilbert Date: Mon, 2 Dec 2024 16:59:43 -0500 Subject: [PATCH 1/3] Update update_monitor_table to use django models --- jwql/utils/monitor_utils.py | 6 +++--- jwql/website/apps/jwql/monitor_models/common.py | 8 +++++++- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/jwql/utils/monitor_utils.py b/jwql/utils/monitor_utils.py index 8eb4c8a16..75f7261fb 100644 --- a/jwql/utils/monitor_utils.py +++ b/jwql/utils/monitor_utils.py @@ -22,11 +22,11 @@ import numpy as np from django import setup -from jwql.database.database_interface import Monitor, engine from jwql.utils.constants import ASIC_TEMPLATES, JWST_DATAPRODUCTS, MAST_QUERY_LIMIT from jwql.utils.constants import ON_GITHUB_ACTIONS, ON_READTHEDOCS from jwql.utils.logging_functions import configure_logging, get_log_status from jwql.utils import mast_utils +from jwql.website.apps.jwql.monitor_models.common import Monitor # Increase the limit on the number of entries that can be returned by @@ -285,5 +285,5 @@ def update_monitor_table(module, start_time, log_file): new_entry['status'] = get_log_status(log_file) new_entry['log_file'] = os.path.basename(log_file) - with engine.begin() as connection: - connection.execute(Monitor.__table__.insert(), new_entry) + entry = Monitor(**new_entry) + entry.save() diff --git a/jwql/website/apps/jwql/monitor_models/common.py b/jwql/website/apps/jwql/monitor_models/common.py index ebcf7c82a..3469c14aa 100644 --- a/jwql/website/apps/jwql/monitor_models/common.py +++ b/jwql/website/apps/jwql/monitor_models/common.py @@ -178,11 +178,17 @@ class Meta: from django.contrib.postgres.fields import ArrayField +class StatusEnum(models.TextChoices): + SUCCESS = "SUCCESS" + FAILURE = "FAILURE" + + class Monitor(models.Model): monitor_name = models.CharField() start_time = models.DateTimeField() end_time = models.DateTimeField(blank=True, null=True) - status = models.TextField(blank=True, null=True) # This field type is a guess. + status = models.EnumField(StatusEnum) + #status = models.TextField(blank=True, null=True) # This field type is a guess. log_file = models.CharField() class Meta: From b299c0fb07a9ea288e31915ecd365c74c2f97f5a Mon Sep 17 00:00:00 2001 From: Bryan Hilbert Date: Mon, 2 Dec 2024 17:12:50 -0500 Subject: [PATCH 2/3] Remove old column definition --- jwql/website/apps/jwql/monitor_models/common.py | 1 - 1 file changed, 1 deletion(-) diff --git a/jwql/website/apps/jwql/monitor_models/common.py b/jwql/website/apps/jwql/monitor_models/common.py index 3469c14aa..18a514675 100644 --- a/jwql/website/apps/jwql/monitor_models/common.py +++ b/jwql/website/apps/jwql/monitor_models/common.py @@ -188,7 +188,6 @@ class Monitor(models.Model): start_time = models.DateTimeField() end_time = models.DateTimeField(blank=True, null=True) status = models.EnumField(StatusEnum) - #status = models.TextField(blank=True, null=True) # This field type is a guess. log_file = models.CharField() class Meta: From 4fd90257df0994f05287e1cb2c56c7801faf0861 Mon Sep 17 00:00:00 2001 From: Bryan Hilbert Date: Mon, 2 Dec 2024 17:19:57 -0500 Subject: [PATCH 3/3] Add enum-related imports --- jwql/website/apps/jwql/monitor_models/common.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/jwql/website/apps/jwql/monitor_models/common.py b/jwql/website/apps/jwql/monitor_models/common.py index 18a514675..f8c3aa0f8 100644 --- a/jwql/website/apps/jwql/monitor_models/common.py +++ b/jwql/website/apps/jwql/monitor_models/common.py @@ -176,9 +176,11 @@ class Meta: # Feel free to rename the models, but don't rename db_table values or field names. from django.db import models from django.contrib.postgres.fields import ArrayField +from django_enum import EnumField +from enum import StrEnum -class StatusEnum(models.TextChoices): +class StatusEnum(StrEnum): SUCCESS = "SUCCESS" FAILURE = "FAILURE" @@ -187,7 +189,7 @@ class Monitor(models.Model): monitor_name = models.CharField() start_time = models.DateTimeField() end_time = models.DateTimeField(blank=True, null=True) - status = models.EnumField(StatusEnum) + status = EnumField(StatusEnum) log_file = models.CharField() class Meta: