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

Auto elog messages from RunControl #221

Open
wants to merge 1 commit 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
32 changes: 32 additions & 0 deletions RunControl/code/RunControlServer.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
from Run import Run
from Logger import Logger
from PadmeDB import PadmeDB
from elog_notify import ElogNotify

class RunControlServer:

Expand All @@ -27,6 +28,8 @@ def __init__(self,mode):
self.lock_file = self.daq_dir+"/run/lock"
self.lus_file = self.daq_dir+"/setup/last_used_setup"

self.elog = ElogNotify('http://padmesrv2.lnf.infn.it:8080/')

# Redefine print to send output to log file
sys.stdout = Logger()
sys.stderr = sys.stdout
Expand Down Expand Up @@ -883,6 +886,19 @@ def start_run(self):
# self.db.set_run_status(self.run.run_number,2) # Status 2: run started

self.send_answer("run_started")
self.elog.log_message('Run',
Author='RunControl',
Subsystem='Run',
Category='General',
Subject='Started run %d'%self.run.run_number,
Text='\n'.join([
'New run started',
'Run number: %d'%self.run.run_number,
'Run type: %s'%self.run.run_type,
'Run crew: %s'%self.run.run_user,
'Run comment: %s'%self.run.run_comment_start,
])
)

# RunControl is now in "running" mode
return "running"
Expand Down Expand Up @@ -926,6 +942,22 @@ def terminate_run(self):

self.run.stop()

self.elog.log_message('Run',
Author='RunControl',
Subsystem='Run',
Category='General',
Subject='Terminated run %d'%self.run.run_number,
Text='\n'.join([
'Run terminated',
'Run number: %d'%self.run.run_number,
'Run type: %s'%self.run.run_type,
'Run crew: %s'%self.run.run_user,
'Start message: %s'%self.run.run_comment_start,
'Stop message: %s'%self.run.run_comment_stop,
])
)

# Run stop_daq procedure for each ADC board
terminate_ok = True

# Run stop_daq procedure for each ADC board
Expand Down
31 changes: 31 additions & 0 deletions RunControl/code/elog_notify.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import requests

class ElogNotify:
def __init__(self, url):
self.url = url
def log_message(self, logbook, **kwargs):
print(kwargs)
fields = dict(kwargs)
fields.update(cmd='Submit')
try:
requests.post(self.url+logbook, files=fields, timeout=.00001)
except:
pass


if __name__ == '__main__':
elog = ElogNotify('http://127.0.0.1:8080/')
elog.log_message('Run',
Author='RunControl',
Subsystem='Run',
Category='General',
Subject='Terminated run %d'%209384092,
Text='\n'.join([
'Run terminated',
'Run number: %d'%209384092,
'Run type: %s'%'self.run.run_type',
'Run crew: %s'%'self.run.run_user',
'Start message: %s'%'self.run.run_comment_start',
'Stop message: %s'%'self.run.run_comment_stop',
])
)