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

1 change: 1 addition & 0 deletions jwql/utils/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -1042,6 +1042,7 @@ class QueryConfigKeys:
MAX_LEN_GRATING = 40
MAX_LEN_INSTRUMENT = 7
MAX_LEN_MNEMONIC = 40
MAX_LEN_MONITOR = 100
MAX_LEN_NGROUPS = 10
MAX_LEN_NINTS = 10
MAX_LEN_OBS = 3
Expand Down
6 changes: 3 additions & 3 deletions jwql/utils/monitor_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
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
Expand All @@ -41,6 +40,7 @@
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "jwql.website.jwql_proj.settings")
setup()
from jwql.website.apps.jwql.models import RootFileInfo
from jwql.website.apps.jwql.monitor_models.common import Monitor


def exclude_asic_tuning(mast_results):
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()
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Generated by Django 5.1.4 on 2025-02-05 15:31

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('jwql', '0029_wispfinderb4queryhistory'),
]

operations = [
migrations.AlterField(
model_name='monitor',
name='log_file',
field=models.CharField(default='empty', help_text='Log file name', max_length=1000),
),
migrations.AlterField(
model_name='monitor',
name='monitor_name',
field=models.CharField(default='empty', help_text='Monitor name', max_length=100),
),
]
14 changes: 12 additions & 2 deletions jwql/website/apps/jwql/monitor_models/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -182,15 +182,25 @@ class Meta:
DEFAULT_MODEL_CHARFIELD,
MAX_LEN_FILTER,
MAX_LEN_INSTRUMENT,
MAX_LEN_MONITOR,
MAX_LEN_PATH
)


class Monitor(models.Model):
monitor_name = models.CharField()
monitor_name = models.CharField(
max_length=MAX_LEN_MONITOR,
help_text="Monitor name",
default=DEFAULT_MODEL_CHARFIELD
)
start_time = models.DateTimeField()
end_time = models.DateTimeField(blank=True, null=True)
status = models.TextField(blank=True, null=True)
log_file = models.CharField()
log_file = models.CharField(
max_length=MAX_LEN_PATH,
help_text="Log file name",
default=DEFAULT_MODEL_CHARFIELD
)

class Meta:
managed = True
Expand Down