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..f8c3aa0f8 100644 --- a/jwql/website/apps/jwql/monitor_models/common.py +++ b/jwql/website/apps/jwql/monitor_models/common.py @@ -176,13 +176,20 @@ 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(StrEnum): + 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 = EnumField(StatusEnum) log_file = models.CharField() class Meta: