-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsesshu.py
67 lines (55 loc) · 1.82 KB
/
sesshu.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
#!/usr/bin/env python
import os
import yaml
import click
import logging
import logging.config
import multiprocessing
from sesshu import worker
from sesshu import config
from sesshu import message
from sesshu import constant
@click.command()
@click.option('--configuration-file', help='Path to YAML configuration file.')
def main(configuration_file):
''' Panorama sesshu. '''
# Determine the configuration file to use.
if configuration_file is None:
configuration_file = os.path.join(
os.path.dirname(__file__), constant.DEFAULT_CONFIGURATION_FILE
)
else:
configuration_file = os.path.join(
os.path.abspath(configuration_file)
)
# Read in the application configuration.
with open(configuration_file, 'r') as f:
configuration = yaml.safe_load(f.read())
config.validate(configuration)
# Configure the logger.
log_path = os.path.join(
configuration['logging']['path'], '{}.log'.format(
configuration['logging']['name']
)
)
logging.basicConfig(
level=logging.INFO,
format='[%(process)d] - %(asctime)s - %(levelname)s - %(message)s',
filename=log_path
)
# Grab a logger.
log = logging.getLogger(configuration['logging']['name'])
log.info(
'The following plugins are enabled: {}'.format(
', '.join(configuration['plugin'])
)
)
# Spawn N workers - per configuration.
log.info('Spawning {} workers'.format(configuration['workers']['count']))
for i in xrange(configuration['workers']['count']):
p = multiprocessing.Process(target=worker.run, args=(configuration,))
p.start()
# TODO: Monitor children and heartbeat to registry.
log.info('All workers created successfully.')
if __name__ == '__main__':
main()