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

Check that the last kadi dwell < 3 days old #48

Merged
merged 2 commits into from
Jun 25, 2021
Merged
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
29 changes: 28 additions & 1 deletion jobwatch/skawatch.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,14 @@
#!/usr/bin/env python

import argparse
import jobwatch
from glob import glob
import astropy.units as u
import time

from cxotime import CxoTime
from kadi import events

import jobwatch
from jobwatch import (FileWatch, JobWatch, DbWatch,
make_html_report, copy_errs,
set_report_attrs)
Expand Down Expand Up @@ -53,6 +59,25 @@ def __init__(self, task, maxage=1, errors=jobwatch.ERRORS, requires=(),
maxage=maxage)


class KadiWatch(JobWatch):
def __init__(self, task, filename, maxage=1):
self.type = 'Application Data'
super().__init__(task, filename, maxage=maxage)

@property
def filelines(self):
return []

@property
def age(self):
if not hasattr(self, '_age'):
last_dwell = events.dwells.all().last()
self.filetime = CxoTime(last_dwell.stop).unix
self.filedate = time.ctime(self.filetime)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is clunky but I didn't see a driver to update the formatting of the rest of the time strings.

self._age = (CxoTime.now() - CxoTime(last_dwell.stop)).to_value(u.day)
return self._age


class SkaDbWatch(DbWatch):
def __init__(self, task, maxage=1, table=None, timekey='tstart'):
super(SkaDbWatch, self).__init__(
Expand Down Expand Up @@ -225,6 +250,8 @@ def main():
dbfile='/proj/sot/ska/data/cmd_states/cmd_states.db3'),
])

jws.extend([KadiWatch('kadi dwells', '/proj/sot/ska/data/kadi/events3.db3', maxage=3)])

set_report_attrs(jws)
index_html = make_html_report(jws, args.rootdir, args.date_now)
recipients = ['aca@head.cfa.harvard.edu']
Expand Down