2013-10-17 22:25:19 +00:00
|
|
|
import logging
|
2013-10-18 19:28:16 +00:00
|
|
|
import daemon
|
2013-10-18 21:52:55 +00:00
|
|
|
import argparse
|
2013-10-17 22:25:19 +00:00
|
|
|
|
2013-10-18 21:27:09 +00:00
|
|
|
from data.queue import image_diff_queue
|
2013-11-13 19:41:20 +00:00
|
|
|
from data.model import DataModelException
|
2013-10-17 22:25:19 +00:00
|
|
|
from endpoints.registry import process_image_changes
|
2013-11-15 20:50:20 +00:00
|
|
|
from workers.worker import Worker
|
2013-10-17 22:25:19 +00:00
|
|
|
|
|
|
|
|
2013-10-20 18:52:56 +00:00
|
|
|
root_logger = logging.getLogger('')
|
|
|
|
root_logger.setLevel(logging.DEBUG)
|
|
|
|
|
|
|
|
FORMAT = '%(asctime)-15s - %(levelname)s - %(pathname)s - %(funcName)s - %(message)s'
|
|
|
|
formatter = logging.Formatter(FORMAT)
|
|
|
|
|
2013-10-17 22:25:19 +00:00
|
|
|
logger = logging.getLogger(__name__)
|
|
|
|
|
|
|
|
|
2013-11-15 20:50:20 +00:00
|
|
|
class DiffsWorker(Worker):
|
|
|
|
def process_queue_item(self, job_details):
|
|
|
|
image_id = job_details['image_id']
|
|
|
|
namespace = job_details['namespace']
|
|
|
|
repository = job_details['repository']
|
2013-10-17 22:25:19 +00:00
|
|
|
|
2013-11-13 19:41:20 +00:00
|
|
|
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)
|
2013-10-18 21:27:09 +00:00
|
|
|
|
2013-11-15 20:50:20 +00:00
|
|
|
return True
|
2013-10-18 21:52:55 +00:00
|
|
|
|
2013-10-20 18:52:56 +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-11-15 20:50:20 +00:00
|
|
|
worker = DiffsWorker(image_diff_queue)
|
|
|
|
|
2013-10-18 21:52:55 +00:00
|
|
|
if args.D:
|
2013-10-20 18:52:56 +00:00
|
|
|
handler = logging.FileHandler(args.log)
|
|
|
|
handler.setFormatter(formatter)
|
|
|
|
root_logger.addHandler(handler)
|
|
|
|
with daemon.DaemonContext(files_preserve=[handler.stream]):
|
2013-11-15 20:50:20 +00:00
|
|
|
worker.start()
|
2013-10-18 21:52:55 +00:00
|
|
|
|
|
|
|
else:
|
2013-10-20 18:52:56 +00:00
|
|
|
handler = logging.StreamHandler()
|
|
|
|
handler.setFormatter(formatter)
|
|
|
|
root_logger.addHandler(handler)
|
2013-11-15 20:50:20 +00:00
|
|
|
worker.start()
|