Fix the diffsworker to run as a daemon.
This commit is contained in:
parent
b2315a4331
commit
0c979cd79f
1 changed files with 32 additions and 17 deletions
|
@ -10,6 +10,13 @@ from data.queue import image_diff_queue
|
||||||
from endpoints.registry import process_image_changes
|
from endpoints.registry import process_image_changes
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
root_logger = logging.getLogger('')
|
||||||
|
root_logger.setLevel(logging.DEBUG)
|
||||||
|
|
||||||
|
FORMAT = '%(asctime)-15s - %(levelname)s - %(pathname)s - %(funcName)s - %(message)s'
|
||||||
|
formatter = logging.Formatter(FORMAT)
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
|
@ -32,20 +39,8 @@ def process_work_items():
|
||||||
logger.debug('No more work.')
|
logger.debug('No more work.')
|
||||||
|
|
||||||
|
|
||||||
parser = argparse.ArgumentParser(description='Worker daemon to compute diffs')
|
def start_worker():
|
||||||
parser.add_argument('-D', action='store_true', default=False,
|
logger.debug("Scheduling worker.")
|
||||||
help='Run the worker in daemon mode.')
|
|
||||||
parser.add_argument('--log', default='diffsworker.log',
|
|
||||||
help='Specify the log file for the worker as a daemon.')
|
|
||||||
args = parser.parse_args()
|
|
||||||
|
|
||||||
def start_worker(args):
|
|
||||||
FORMAT = '%(asctime)-15s - %(levelname)s - %(pathname)s - %(funcName)s - %(message)s'
|
|
||||||
|
|
||||||
if args.D:
|
|
||||||
logging.basicConfig(filename=args.log, format=FORMAT, level=logging.DEBUG)
|
|
||||||
else:
|
|
||||||
logging.basicConfig(format=FORMAT, level=logging.DEBUG)
|
|
||||||
|
|
||||||
sched = Scheduler()
|
sched = Scheduler()
|
||||||
sched.start()
|
sched.start()
|
||||||
|
@ -55,9 +50,29 @@ def start_worker(args):
|
||||||
while True:
|
while True:
|
||||||
time.sleep(60 * 60 * 24) # sleep one day, basically forever
|
time.sleep(60 * 60 * 24) # sleep one day, basically forever
|
||||||
|
|
||||||
|
|
||||||
|
parser = argparse.ArgumentParser(description='Worker daemon to compute diffs')
|
||||||
|
parser.add_argument('-D', action='store_true', default=False,
|
||||||
|
help='Run the worker in daemon mode.')
|
||||||
|
parser.add_argument('--log', default='diffsworker.log',
|
||||||
|
help='Specify the log file for the worker as a daemon.')
|
||||||
|
args = parser.parse_args()
|
||||||
|
|
||||||
|
|
||||||
|
# if not args.D:
|
||||||
|
# else:
|
||||||
|
# logging.basicConfig(format=FORMAT, level=logging.DEBUG)
|
||||||
|
# start_worker(args)
|
||||||
|
|
||||||
if args.D:
|
if args.D:
|
||||||
with daemon.DaemonContext():
|
handler = logging.FileHandler(args.log)
|
||||||
start_worker(args)
|
handler.setFormatter(formatter)
|
||||||
|
root_logger.addHandler(handler)
|
||||||
|
with daemon.DaemonContext(files_preserve=[handler.stream]):
|
||||||
|
start_worker()
|
||||||
|
|
||||||
else:
|
else:
|
||||||
start_worker(args)
|
handler = logging.StreamHandler()
|
||||||
|
handler.setFormatter(formatter)
|
||||||
|
root_logger.addHandler(handler)
|
||||||
|
start_worker()
|
Reference in a new issue