This repository has been archived on 2020-03-24. You can view files and clone it, but cannot push or open issues or pull requests.
quay/workers/diffsworker.py

63 lines
1.5 KiB
Python
Raw Normal View History

import logging
import json
2013-10-18 19:28:16 +00:00
import daemon
import time
2013-10-18 21:52:55 +00:00
import argparse
from apscheduler.scheduler import Scheduler
from data.queue import image_diff_queue
from endpoints.registry import process_image_changes
logger = logging.getLogger(__name__)
def process_work_items():
logger.debug('Getting work item from queue.')
2013-10-18 19:28:16 +00:00
item = image_diff_queue.get()
if item:
logger.debug('Queue gave us some work: %s' % item.body)
request = json.loads(item.body)
process_image_changes(request['namespace'], request['repository'],
request['image_id'])
image_diff_queue.complete(item)
else:
logger.debug('No work today.')
2013-10-18 21:52:55 +00:00
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()
2013-10-18 21:52:55 +00:00
def start_worker(args):
FORMAT = '%(asctime)-15s - %(levelname)s - %(pathname)s - %(funcName)s - %(message)s'
2013-10-18 19:28:16 +00:00
2013-10-18 21:52:55 +00:00
if args.D:
logging.basicConfig(filename=args.log, format=FORMAT, level=logging.DEBUG)
else:
logging.basicConfig(format=FORMAT, level=logging.DEBUG)
sched = Scheduler()
sched.start()
sched.add_interval_job(process_work_items, seconds=10)
while True:
time.sleep(60 * 60 * 24) # sleep one day, basically forever
if args.D:
with daemon.DaemonContext():
start_worker(args)
else:
start_worker(args)