48 lines
No EOL
1.4 KiB
Python
48 lines
No EOL
1.4 KiB
Python
import logging
|
|
import argparse
|
|
|
|
from data.queue import image_diff_queue
|
|
from data.model import DataModelException
|
|
from endpoints.registry import process_image_changes
|
|
from workers.worker import Worker
|
|
|
|
|
|
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__)
|
|
|
|
|
|
class DiffsWorker(Worker):
|
|
def process_queue_item(self, job_details):
|
|
image_id = job_details['image_id']
|
|
namespace = job_details['namespace']
|
|
repository = job_details['repository']
|
|
|
|
try:
|
|
process_image_changes(namespace, repository, image_id)
|
|
except DataModelException:
|
|
# This exception is unrecoverable, and the item should continue and be
|
|
# marked as complete.
|
|
msg = ('Image does not exist in database \'%s\' for repo \'%s/\'%s\'' %
|
|
(image_id, namespace, repository))
|
|
logger.warning(msg)
|
|
|
|
return True
|
|
|
|
parser = argparse.ArgumentParser(description='Worker daemon to compute diffs')
|
|
parser.add_argument('--log', help='Specify the log file for the worker as a daemon.')
|
|
args = parser.parse_args()
|
|
|
|
if args.log is not None:
|
|
handler = logging.FileHandler(args.log)
|
|
else:
|
|
handler = logging.StreamHandler()
|
|
handler.setFormatter(formatter)
|
|
root_logger.addHandler(handler)
|
|
|
|
worker = DiffsWorker(image_diff_queue)
|
|
worker.start() |