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

no async for manual and 2nd MR changes

parent 354c2a6a
No related branches found
No related tags found
1 merge request!93feat/reportservice
import argparse
import asyncio import asyncio
from datetime import datetime, timedelta from datetime import datetime, timedelta
import logging import logging
import urllib.parse
from dateutil import parser, tz from dateutil import parser, tz
import yaml import yaml
...@@ -10,10 +12,10 @@ import zmq.asyncio ...@@ -10,10 +12,10 @@ import zmq.asyncio
async def auto_run(): async def auto_run():
""" """
Run the report service automatically depending on the scheduled times Run the report service automatically depending on the scheduled times
in the run_time list, read from the config yaml file (cal_conf.yaml) in the run_time list, read from the config yaml file (report_conf.yaml)
""" """
with open("cal_conf.yaml", 'r') as ymlfile: with open("report_conf.yaml", 'r') as ymlfile:
cfg = yaml.load(ymlfile) cfg = yaml.load(ymlfile)
# time index that points at a timestamp, when the next # time index that points at a timestamp, when the next
...@@ -55,15 +57,14 @@ async def auto_run(): ...@@ -55,15 +57,14 @@ async def auto_run():
await asyncio.sleep(600) await asyncio.sleep(600)
arg_parser = argparse.ArgumentParser(description='Automatic Launch')
arg_parser.add_argument('--config-file', type=str, default='./report_conf.yaml')
parser = argparse.ArgumentParser(description='Start the report service') arg_parser.add_argument('--log-file', type=str, default='./report.log')
parser.add_argument('--config-file', type=str, default='./cal_conf.yaml') arg_parser.add_argument('--logging', type=str, default="INFO",
parser.add_argument('--log-file', type=str, default='./report.log')
parser.add_argument('--logging', type=str, default="INFO",
choices=['INFO', 'DEBUG', 'ERROR']) choices=['INFO', 'DEBUG', 'ERROR'])
if __name__ == "__main__": if __name__ == "__main__":
args = vars(parser.parse_args()) args = vars(arg_parser.parse_args())
conf_file = args["config_file"] conf_file = args["config_file"]
with open(conf_file, "r") as f: with open(conf_file, "r") as f:
config = yaml.load(f.read()) config = yaml.load(f.read())
...@@ -75,11 +76,6 @@ if __name__ == "__main__": ...@@ -75,11 +76,6 @@ if __name__ == "__main__":
level=getattr(logging, args['logging']), level=getattr(logging, args['logging']),
format='%(levelname)-6s: %(asctime)s %(message)s', format='%(levelname)-6s: %(asctime)s %(message)s',
datefmt='%Y-%m-%d %H:%M:%S') datefmt='%Y-%m-%d %H:%M:%S')
logfile = './report.log'
logging.basicConfig(filename=logfile, filemode='a+',
level=logging.INFO,
format='%(levelname)-6s: %(asctime)s %(message)s',
datefmt='%Y-%m-%d %H:%M:%S')
loop = asyncio.get_event_loop() loop = asyncio.get_event_loop()
loop.run_until_complete(auto_run()) loop.run_until_complete(auto_run())
......
import asyncio import argparse
import logging import logging
import os import os
import sys import sys
import urllib.parse
import yaml import yaml
import zmq import zmq
import zmq.asyncio import zmq.asyncio
logfile = './report.log'
logging.basicConfig(filename=logfile, filemode='a+',
level=logging.INFO,
format='%(levelname)-6s: %(asctime)s %(message)s',
datefmt='%Y-%m-%d %H:%M:%S')
def manual_run(req_conf):
async def manual_run(req_conf):
""" """
Run the report service manually from any machine Run the report service manually from any machine
and provide the requested configuration for and provide the requested configuration for
...@@ -24,21 +19,41 @@ async def manual_run(req_conf): ...@@ -24,21 +19,41 @@ async def manual_run(req_conf):
requested Instruments. This list can requested Instruments. This list can
contain the Instruments names e.g ['SPB'] contain the Instruments names e.g ['SPB']
or ['all'] for generating reports for all or ['all'] for generating reports for all
instruments in the "cal_conf.yaml". instruments in the "report_conf.yaml".
This can also be a customized conf. file(dict) This can also be a customized conf. file(dict)
for test purposes. for test purposes.
""" """
with open("cal_conf.yaml", 'r') as ymlfile: with open("report_conf.yaml", 'r') as ymlfile:
cfg = yaml.load(ymlfile) cfg = yaml.load(ymlfile)
port = cfg['GLOBAL']['server-port'] port = cfg['GLOBAL']['server-port']
con = zmq.asyncio.Context() con = zmq.Context()
socket = con.socket(zmq.REQ) socket = con.socket(zmq.REQ)
con = socket.connect(port) con = socket.connect(port)
await socket.send_pyobj(req_conf) socket.send_pyobj(req_conf)
msg = await socket.recv_pyobj() msg = socket.recv_pyobj()
logging.info('{} Manual Run'.format(msg)) logging.info('{} Manual Run'.format(msg))
arg_parser = argparse.ArgumentParser(description='Manual Launch')
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",
choices=['INFO', 'DEBUG', 'ERROR'])
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())
logfile = args["log_file"]
fmt = '%(asctime)s - %(name)s - %(levelname)s - %(message)s'
logging.basicConfig(filename=logfile, filemode='a+',
level=getattr(logging, args['logging']),
format='%(levelname)-6s: %(asctime)s %(message)s',
datefmt='%Y-%m-%d %H:%M:%S')
manual_run(['all'])
...@@ -6,8 +6,8 @@ GLOBAL: ...@@ -6,8 +6,8 @@ GLOBAL:
server-port: "tcp://max-exfl015:5555" server-port: "tcp://max-exfl015:5555"
run-on: run-on:
- Monday 08:30:00 UTC - Friday 08:30:00 UTC
- Thursday 10:33:00 UTC - Friday 10:33:00 UTC
report-service: report-service:
port: 5555 port: 5555
......
...@@ -155,13 +155,13 @@ async def server_runner(config): ...@@ -155,13 +155,13 @@ async def server_runner(config):
while True: while True:
response = await socket.recv_pyobj() response = await socket.recv_pyobj()
socket.send_pyobj('Build DC reports through -->') await socket.send_pyobj('Build DC reports through -->')
logging.info("response: {}".format(response)) logging.info("response: {}".format(response))
# Check if response is a list or a dict. # Check if response is a list or a dict.
# if list, it should either have instrument names or ['all']. # if list, it should either have instrument names or ['all'].
# if dict, it should acquires the details of the requested reports # if dict, it should acquires the details of the requested reports
# for generation. As it will be used instead of cal_conf.yaml # for generation. As it will be used instead of report_conf.yaml
# reports config file # reports config file
req_cfg = {} req_cfg = {}
...@@ -172,7 +172,7 @@ async def server_runner(config): ...@@ -172,7 +172,7 @@ async def server_runner(config):
if len(response) == 1 and response[0] == 'all': if len(response) == 1 and response[0] == 'all':
req_cfg = config req_cfg = config
else: else:
req_cfg['GLOBAL'] = config[instr] req_cfg['GLOBAL'] = config['GLOBAL']
for instr in response: for instr in response:
try: try:
req_cfg[instr] = config[instr] req_cfg[instr] = config[instr]
...@@ -268,14 +268,14 @@ async def server_runner(config): ...@@ -268,14 +268,14 @@ async def server_runner(config):
logging.error(str(e)) logging.error(str(e))
break break
parser = argparse.ArgumentParser(description='Start the report service') arg_parser = argparse.ArgumentParser(description='Start the report service')
parser.add_argument('--config-file', type=str, default='./cal_conf.yaml') arg_parser.add_argument('--config-file', type=str, default='./report_conf.yaml')
parser.add_argument('--log-file', type=str, default='./report.log') arg_parser.add_argument('--log-file', type=str, default='./report.log')
parser.add_argument('--logging', type=str, default="INFO", arg_parser.add_argument('--logging', type=str, default="INFO",
choices=['INFO', 'DEBUG', 'ERROR']) choices=['INFO', 'DEBUG', 'ERROR'])
if __name__ == "__main__": if __name__ == "__main__":
args = vars(parser.parse_args()) args = vars(arg_parser.parse_args())
conf_file = args["config_file"] conf_file = args["config_file"]
with open(conf_file, "r") as f: with open(conf_file, "r") as f:
config = yaml.load(f.read()) config = yaml.load(f.read())
......
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