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

Make into a package #41

Merged
merged 11 commits into from
Jan 11, 2021
Merged
Changes from 5 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
22 changes: 0 additions & 22 deletions Makefile

This file was deleted.

12 changes: 12 additions & 0 deletions jobwatch/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import ska_helpers
__version__ = ska_helpers.get_version(__package__)

from .jobwatch import *

def test(*args, **kwargs):
'''
Run py.test unit tests.
'''
import testr
return testr.test(*args, **kwargs)

File renamed without changes.
156 changes: 81 additions & 75 deletions hourly_watch.py → jobwatch/hourly_watch.py
Original file line number Diff line number Diff line change
@@ -21,6 +21,23 @@
FILEDIR = os.path.dirname(__file__)


def get_options():
parser = argparse.ArgumentParser(description='Replan Central monitor')
jeanconn marked this conversation as resolved.
Show resolved Hide resolved
parser.add_argument('--date-now',
help='Processing date')
parser.add_argument('--rootdir',
default='.',
help='Output root directory')
parser.add_argument('--email',
action='store_true',
help='Send email report')
parser.add_argument('--loud',
action='store_true',
help='Send email report')
jeanconn marked this conversation as resolved.
Show resolved Hide resolved
args = parser.parse_args()
return args


# Ska-specific watchers
class SkaURLWatch(JobWatch):
def __init__(self, task, maxage_hours, url=None,):
@@ -34,7 +51,7 @@ def headers(self):

try:
response = requests.get(self.basename)
except:
except Exception:
self._exists = False
self._headers = None
else:
@@ -61,7 +78,8 @@ def age(self):
# zone. Finally subtract the two to get an age.
tm = time.strptime(self.headers[time_header],
"%a, %d %b %Y %H:%M:%S %Z")
dtm_url = datetime(tm.tm_year, tm.tm_mon, tm.tm_mday, tm.tm_hour, tm.tm_min, tm.tm_sec,
dtm_url = datetime(tm.tm_year, tm.tm_mon, tm.tm_mday, tm.tm_hour,
tm.tm_min, tm.tm_sec,
tzinfo=pytz.timezone(tm.tm_zone))
# Current local time; .astimezone() makes this explicitly tz-aware
dtm_now_local = datetime.now().astimezone()
@@ -136,76 +154,64 @@ def age(self):
return self._age


parser = argparse.ArgumentParser(description='Replan Central monitor')
parser.add_argument('--date-now',
help='Processing date')
parser.add_argument('--rootdir',
default='.',
help='Output root directory')
parser.add_argument('--email',
action='store_true',
help='Send email report')
parser.add_argument('--loud',
action='store_true',
help='Send email report')
args = parser.parse_args()

jobwatch.LOUD = args.loud


jws = []
jws.extend(
[
SkaURLWatch('kadi', 1, 'http://kadi.cfa.harvard.edu'),
SkaURLWatch('arc', 1, 'http://cxc.harvard.edu/mta/ASPECT/arc/index.html'),
SkaURLWatch('arc', 1, 'http://cxc.harvard.edu/mta/ASPECT/arc/timeline.png'),
SkaURLWatch('arc', 20, 'http://cxc.harvard.edu/mta/ASPECT/arc/ACE_5min.gif'),
#SkaURLWatch('arc', 2, 'http://cxc.harvard.edu/mta/ASPECT/arc/GOES_5min.gif'),
#SkaURLWatch('arc', 2, 'http://cxc.harvard.edu/mta/ASPECT/arc/GOES_xray.gif'),
#SkaURLWatch('arc', 1, 'http://cxc.harvard.edu/mta/ASPECT/arc/hrc_shield.png'),
H5Watch('arc', 1, 'ACE.h5'),
#H5Watch('arc', 1, 'hrc_shield.h5'),
#H5Watch('arc', 1, 'GOES_X.h5'),
IfotFileWatch('arc', 1, 'comm'),
IfotFileWatch('arc', 1, 'eclipse'),
IfotFileWatch('arc', 1, 'grating'),
IfotFileWatch('arc', 1, 'grating'),
IfotFileWatch('arc', 1, 'load_segment'),
IfotFileWatch('arc', 1, 'maneuver'),
IfotFileWatch('arc', 1, 'momentum_mon'),
IfotFileWatch('arc', 1, 'or_er'),
IfotFileWatch('arc', 1, 'radmon'),
IfotFileWatch('arc', 1, 'safe'),
IfotFileWatch('arc', 1, 'sim'),
IfotFileWatch('arc', 1, 'sun_pos_mon'),
NonSkaFileWatch('mta snapshot', 1, '/data/mta4/www/Snapshot/chandra.snapshot'),
SkaWebWatch('arc', 1, 'index.html'),
SkaWebWatch('arc', 1, 'chandra.snapshot'),
#SkaWebWatch('arc', 1, 'hrc_shield.png'),
#SkaWebWatch('arc', 2, 'GOES_xray.gif'),
#SkaWebWatch('arc', 2, 'GOES_5min.gif'),
SkaWebWatch('arc', 20, 'ACE_5min.gif')])

set_report_attrs(jws)
# Are all the reports OK?
report_ok = all([j.ok for j in jws])
errors = [job.basename for job in jws if not job.ok]
# Set the age strings manually to display in hours
for jw in jws:
jw.age_str = '{:.2f}'.format(jw.age / HOURS) if jw.exists else 'None'
index_html = make_html_report(jws, args.rootdir,
index_template=os.path.join(FILEDIR,
'hourly_template.html'),
just_status=True
)
recipients = ['aca@head.cfa.harvard.edu',
'msobolewska@cfa.harvard.edu', 'tisobe@cfa.harvard.edu', 'swolk@cfa.harvard.edu',
'lina.pulgarin-duque@cfa.harvard.edu']

if args.email and not report_ok:
jobwatch.sendmail(
recipients, index_html, args.date_now,
subject="{} Week {} errors: {}".format(
time.strftime("%Y", time.localtime()),
time.strftime("%W", time.localtime()),
", ".join(errors)))
def main():

args = get_options()
jobwatch.LOUD = args.loud

jws = []
jws.extend(
[
SkaURLWatch('kadi', 1, 'http://kadi.cfa.harvard.edu'),
SkaURLWatch('arc', 1, 'http://cxc.harvard.edu/mta/ASPECT/arc/index.html'),
SkaURLWatch('arc', 1, 'http://cxc.harvard.edu/mta/ASPECT/arc/timeline.png'),
SkaURLWatch('arc', 20, 'http://cxc.harvard.edu/mta/ASPECT/arc/ACE_5min.gif'),
# SkaURLWatch('arc', 2, 'http://cxc.harvard.edu/mta/ASPECT/arc/GOES_5min.gif'),
# SkaURLWatch('arc', 2, 'http://cxc.harvard.edu/mta/ASPECT/arc/GOES_xray.gif'),
# SkaURLWatch('arc', 1, 'http://cxc.harvard.edu/mta/ASPECT/arc/hrc_shield.png'),
H5Watch('arc', 1, 'ACE.h5'),
# H5Watch('arc', 1, 'hrc_shield.h5'),
# H5Watch('arc', 1, 'GOES_X.h5'),
IfotFileWatch('arc', 1, 'comm'),
IfotFileWatch('arc', 1, 'eclipse'),
IfotFileWatch('arc', 1, 'grating'),
IfotFileWatch('arc', 1, 'grating'),
IfotFileWatch('arc', 1, 'load_segment'),
IfotFileWatch('arc', 1, 'maneuver'),
IfotFileWatch('arc', 1, 'momentum_mon'),
IfotFileWatch('arc', 1, 'or_er'),
IfotFileWatch('arc', 1, 'radmon'),
IfotFileWatch('arc', 1, 'safe'),
IfotFileWatch('arc', 1, 'sim'),
IfotFileWatch('arc', 1, 'sun_pos_mon'),
NonSkaFileWatch('mta snapshot', 1, '/data/mta4/www/Snapshot/chandra.snapshot'),
SkaWebWatch('arc', 1, 'index.html'),
SkaWebWatch('arc', 1, 'chandra.snapshot'),
# SkaWebWatch('arc', 1, 'hrc_shield.png'),
# SkaWebWatch('arc', 2, 'GOES_xray.gif'),
# SkaWebWatch('arc', 2, 'GOES_5min.gif'),
SkaWebWatch('arc', 20, 'ACE_5min.gif')])

set_report_attrs(jws)
# Are all the reports OK?
report_ok = all([j.ok for j in jws])
errors = [job.basename for job in jws if not job.ok]
# Set the age strings manually to display in hours
for jw in jws:
jw.age_str = '{:.2f}'.format(jw.age / HOURS) if jw.exists else 'None'
index_html = make_html_report(jws, args.rootdir,
index_template=os.path.join(FILEDIR,
'hourly_template.html'),
just_status=True
)
recipients = ['aca@head.cfa.harvard.edu',
'msobolewska@cfa.harvard.edu', 'tisobe@cfa.harvard.edu', 'swolk@cfa.harvard.edu',
'lina.pulgarin-duque@cfa.harvard.edu']

if args.email and not report_ok:
jobwatch.sendmail(
recipients, index_html, args.date_now,
subject="{} Week {} errors: {}".format(
time.strftime("%Y", time.localtime()),
time.strftime("%W", time.localtime()),
", ".join(errors)))
File renamed without changes.
6 changes: 3 additions & 3 deletions jobwatch.py → jobwatch/jobwatch.py
Original file line number Diff line number Diff line change
@@ -35,7 +35,7 @@ def __init__(self, task, filename,
self.maxage = maxage
self.filetime = None
self.filedate = None

self.type = 'Job'
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 hack was to make a test pass, but I think I should probably just update the code in reporting that looks for a "jw.type" and skip if type is missing.

Copy link
Member

Choose a reason for hiding this comment

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

Does it work if you assign None. This would be a bit more agnostic.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

No, None didn't work. And setting it to 'Job' seemed to just override the rest of the types. I didn't have the brainpower just now to figure out the inheritance and just updated the logic in the html report method for now.

self.check()

@property
@@ -183,7 +183,7 @@ def set_report_attrs(jobwatches):
for _, line, _ in jw.found_errors[:maxerrs]]
if len(jw.found_errors) > maxerrs:
popups.append('AND {} MORE'.format(
len(jw.found_errors) - maxerrs))
len(jw.found_errors) - maxerrs))
popup = '<br/>'.join(popups)
jw.overlib = ('ONMOUSEOVER="return overlib (\'{}\', WIDTH, 600);" '
'ONMOUSEOUT="return nd();"'.format(popup))
@@ -224,7 +224,7 @@ def make_html_report(jobwatches, rootdir, datenow=None,
nextdir = (DateTime(datenow) + 1).greta[:7]
outdir = os.path.join(rootdir, currdir)
if not os.path.exists(outdir):
os.mkdir(outdir)
os.makedirs(outdir)

log_template = jinja2.Template(open(LOG_TEMPLATE, 'r').read())
root_prefix = '../{}/'
File renamed without changes.
Loading