Fix test_queue.py tests

This restores the reporter class as was before the metrics changes.
This commit is contained in:
Matt Jibson 2015-08-17 17:22:46 -04:00
parent 3f6f5162e8
commit fc671f3dde
2 changed files with 18 additions and 9 deletions

View file

@ -13,11 +13,22 @@ class NoopWith:
def __exit__(self, type, value, traceback):
pass
class MetricQueueReporter(object):
def __init__(self, metric_queue):
self._metric_queue = metric_queue
def __call__(self, currently_processing, running_count, total_count):
need_capacity_count = total_count - running_count
self._metric_queue.put('BuildCapacityShortage', need_capacity_count, unit='Count')
building_percent = 100 if currently_processing else 0
self._metric_queue.put('PercentBuilding', building_percent, unit='Percent')
class WorkQueue(object):
def __init__(self, queue_name, transaction_factory,
canonical_name_match_list=None, metric_queue=None):
canonical_name_match_list=None, reporter=None):
self._queue_name = queue_name
self._metric_queue = metric_queue
self._reporter = reporter
self._transaction_factory = transaction_factory
self._currently_processing = False
@ -75,14 +86,12 @@ class WorkQueue(object):
return (running_count, available_not_running_count, available_count)
def update_metrics(self):
if self._metric_queue is None:
if self._reporter is None:
return
(running_count, available_not_running_count, available_count) = self.get_metrics()
self._metric_queue.put('BuildCapacityShortage', available_not_running_count, unit='Count')
building_percent = 100 if self._currently_processing else 0
self._metric_queue.put('PercentBuilding', building_percent, unit='Percent')
self._reporter(self._currently_processing, running_count,
running_count + available_not_running_count)
def has_retries_remaining(self, item_id):
""" Returns whether the queue item with the given id has any retries remaining. If the