Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update update_monitor_table() to use django models #1659

Open
wants to merge 3 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions jwql/utils/monitor_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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()
9 changes: 8 additions & 1 deletion jwql/website/apps/jwql/monitor_models/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
Loading