buildman: address PR #11 comments

This commit is contained in:
Jimmy Zelinskie 2015-02-18 14:13:36 -05:00
parent 5790d7d8cc
commit f53dea46b7
5 changed files with 55 additions and 55 deletions

View file

@ -1,5 +1,6 @@
from trollius import From
from buildman.enums import BuildJobResult
from util.cloudwatch import get_queue
@ -28,6 +29,9 @@ class CloudWatchBuildReporter(BuildReporter):
Implements a BuildReporter for Amazon's CloudWatch.
"""
def __init__(self, queue, namespace_name, completed_name, failed_name, incompleted_name):
if None in (queue, namespace_name, completed_name, failed_name, incompleted_name):
raise TypeError
self._queue = queue
self._namespace_name = namespace_name
self._completed_name = completed_name
@ -35,11 +39,11 @@ class CloudWatchBuildReporter(BuildReporter):
self._incompleted_name = incompleted_name
def report_completion_status(self, status):
if status == 'complete':
if status == BuildJobResult.COMPLETE:
status_name = self._completed_name
elif status == 'error':
elif status == BuildJobResult.ERROR:
status_name = self._failed_name
elif status == 'incomplete':
elif status == BuildJobResult.INCOMPLETE:
status_name = self._incompleted_name
else:
return
@ -53,9 +57,8 @@ class BuildMetrics(object):
"""
def __init__(self, app=None):
self._app = app
if app is None:
self._reporter = None
else:
self._reporter = NullReporter()
if app is not None:
reporter_type = app.config.get('BUILD_METRICS_TYPE', 'Null')
if reporter_type == 'CloudWatch':
namespace = app.config.get('BUILD_METRICS_NAMESPACE')
@ -65,8 +68,6 @@ class BuildMetrics(object):
request_queue = get_queue(app)
self._reporter = CloudWatchBuildReporter(request_queue, namespace, completed_name,
failed_name, incompleted_name)
else:
self._reporter = NullReporter()
def __getattr__(self, name):
return getattr(self._reporter, name, None)