diff --git a/reportservice/automatic_run.py b/reportservice/automatic_run.py index 87e57602a5231789629595c5cc1d9e203de76520..0f3b79cac23d511f543421b089647d4077c567c8 100644 --- a/reportservice/automatic_run.py +++ b/reportservice/automatic_run.py @@ -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() diff --git a/reportservice/manual_run.py b/reportservice/manual_run.py index 6b29d18bf9b9825d1806a43d14312a46528ea5e1..2c6b9293d19b07d211060a65531c9f3c1f0b2e8b 100644 --- a/reportservice/manual_run.py +++ b/reportservice/manual_run.py @@ -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)