-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlaunch.py
74 lines (57 loc) · 2.4 KB
/
launch.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import argparse
import json
import logging
import os
import platform
import watchtower
import yamlconf
from monitor.Monitor import Monitor
from monitor.QueueManager import QueueManager
from monitor.client.BackendClient import BackendClient
fmt = '%(levelname)-8s | %(asctime)s | %(threadName)10s | %(filename)-20s:(%(lineno)3s) %(funcName)-20s | %(message)s'
logging.basicConfig(format=fmt, level='INFO')
logger = logging.getLogger()
if not logger.handlers:
h = watchtower.CloudWatchLogHandler(
log_group_name=f'/lcb/monitor/{platform.node()}',
log_group_retention_days=3,
send_interval=30)
logger.addHandler(h)
if __name__ == "__main__":
parser = argparse.ArgumentParser()
parser.add_argument('-c', '--config', type=str, default='appconfig.yml',
help='path to the yaml configuration file to use (default: ./appconfig.yml)')
parser.add_argument('-t', '--test', action='store_true',
help='run in test mode, no data will be converted or sent to aws. This '
'overrides the -c option to use \'appconfig-test.yml\'')
parser.add_argument('--debug', action='store_true')
args = parser.parse_args()
if args.config:
configFile = args.config
else:
configFile = 'appconfig.yml'
stage = 'prod'
if args.test:
stage = 'test'
configFile = 'appconfig-test.yml'
logger.warning('\nRunning in TEST mode !!!\n')
with open(configFile, 'r') as stream:
config = yamlconf.load(stream)
config['test'] = args.test
config['debug'] = args.debug
if os.path.exists(config['monitor']['msconvert']):
logger.info('Found ProteoWizard')
else:
logger.error(f"Can't find ProteoWizard at {config['monitor']['msconvert']}")
exit(1)
backend_cli = BackendClient(config, os.getenv(config['backend']['url_var'], "https://test-api.metabolomics.us"),
os.getenv(config['backend']['api_key_var'], "9MjbJRbAtj8spCJJVTPbP3YWc4wjlW0c7AP47Pmi"))
if backend_cli:
logger.info(f'Backend client initialized. (url: {backend_cli._url})')
if args.debug:
logger.debug('Running in debug mode')
logger.debug('Configuration: ' + json.dumps(config, indent=2))
queue_mgr = QueueManager(stage)
Monitor(config, backend_cli, queue_mgr).run()