-
Notifications
You must be signed in to change notification settings - Fork 8
/
pipeline_daemon.py
45 lines (32 loc) · 1.07 KB
/
pipeline_daemon.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
import argparse
import sys
import os
import signal
import logging
import time
import pdb
from sprocket.config import settings
from sprocket.service import pipeline_server
def start_daemon():
"""A blocking call to start servicing pipeline"""
pipeline_server.serve()
while True:
time.sleep(3600) # we need to keep the the only non-daemon thread running
def shutdown(*args):
logging.info("Shutting down daemon")
pipeline_server.stop(0)
def main():
parser = argparse.ArgumentParser()
parser.add_argument("-l", "--log", help="logging level", default='INFO')
args, _ = parser.parse_known_args()
numeric_level = getattr(logging, args.log.upper(), None)
if not isinstance(numeric_level, int):
raise ValueError('Invalid log level: %s' % args.log)
logging.basicConfig(level=numeric_level, format="%(levelname)s - %(asctime)s - %(filename)s:%(lineno)d - %(message)s")
logging.debug("config: %s", settings)
try:
start_daemon()
except KeyboardInterrupt:
os._exit(0)
if __name__ == '__main__':
main()