Skip to content
Snippets Groups Projects
Commit bb49781f authored by Karim Ahmed's avatar Karim Ahmed
Browse files

add config from manual_run and review fixes

parent c28bb534
No related branches found
No related tags found
1 merge request!93feat/reportservice
......@@ -9,15 +9,12 @@ import yaml
import zmq
import zmq.asyncio
async def auto_run():
async def auto_run(cfg):
"""
Run the report service automatically depending on the scheduled times
in the run_time list, read from the config yaml file (report_conf.yaml)
"""
with open("report_conf.yaml", 'r') as ymlfile:
cfg = yaml.load(ymlfile)
# time index that points at a timestamp, when the next
# report service run takes place.
tidx = 0
......@@ -67,7 +64,7 @@ if __name__ == "__main__":
args = vars(arg_parser.parse_args())
conf_file = args["config_file"]
with open(conf_file, "r") as f:
config = yaml.load(f.read())
cfg = yaml.load(f.read())
logfile = args["log_file"]
fmt = '%(asctime)s - %(name)s - %(levelname)s - %(message)s'
......@@ -78,5 +75,5 @@ if __name__ == "__main__":
datefmt='%Y-%m-%d %H:%M:%S')
loop = asyncio.get_event_loop()
loop.run_until_complete(auto_run())
loop.run_until_complete(auto_run(cfg))
loop.close()
......@@ -6,16 +6,15 @@ import urllib.parse
import yaml
import zmq
import zmq.asyncio
def manual_run(req_instr):
def manual_run(request, cfg):
"""
Run the report service manually from any machine
and provide the requested configuration for
reports generation.
:param req_instr: a list for generating reports for the
:param request: a list for generating reports for the
requested Instruments. This list can
contain the Instruments names e.g ['SPB']
or ['all'] for generating reports for all
......@@ -25,19 +24,18 @@ def manual_run(req_instr):
for test purposes.
"""
with open("report_conf.yaml", 'r') as ymlfile:
cfg = yaml.load(ymlfile)
port = cfg['GLOBAL']['server-port']
con = zmq.Context()
socket = con.socket(zmq.REQ)
con = socket.connect(port)
socket.send_pyobj(req_instr)
socket.send_pyobj(request)
msg = socket.recv_pyobj()
logging.info('{} Manual Run'.format(msg))
arg_parser = argparse.ArgumentParser(description='Manual Launch')
arg_parser.add_argument('--instrument', default=['all'], nargs='+')
arg_parser.add_argument('--testing', dest='testing', action='store_true')
arg_parser.set_defaults(testing=False)
arg_parser.add_argument('--config-file', type=str, default='./report_conf.yaml')
arg_parser.add_argument('--log-file', type=str, default='./report.log')
arg_parser.add_argument('--logging', type=str, default="INFO",
......@@ -47,7 +45,7 @@ if __name__ == "__main__":
args = vars(arg_parser.parse_args())
conf_file = args["config_file"]
with open(conf_file, "r") as f:
config = yaml.load(f.read())
cfg = yaml.load(f.read())
logfile = args["log_file"]
fmt = '%(asctime)s - %(name)s - %(levelname)s - %(message)s'
......@@ -56,5 +54,9 @@ if __name__ == "__main__":
level=getattr(logging, args['logging']),
format='%(levelname)-6s: %(asctime)s %(message)s',
datefmt='%Y-%m-%d %H:%M:%S')
if args["testing"]:
request = cfg
else:
request = args["instrument"]
manual_run(args["instrument"])
manual_run(request, cfg)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment