Various small fixes

This commit is contained in:
Joseph Schorr 2014-11-18 16:34:09 -05:00
parent 6df6f28edf
commit 63f2e7794f
3 changed files with 20 additions and 17 deletions

View file

@ -1,4 +1,5 @@
import datetime
import time
import logging
import json
import trollius
@ -31,20 +32,19 @@ class ComponentStatus(object):
class BuildComponent(BaseComponent):
""" An application session component which conducts one (or more) builds. """
server_hostname = None
expected_token = None
builder_realm = None
_component_status = ComponentStatus.JOINING
_last_heartbeat = None
_current_job = None
_build_status = None
_image_info = None
def __init__(self, config, realm=None, token=None, **kwargs):
self.expected_token = token
self.builder_realm = realm
self.parent_manager = None
self.server_hostname = None
self._component_status = ComponentStatus.JOINING
self._last_heartbeat = None
self._current_job = None
self._build_status = None
self._image_info = None
BaseComponent.__init__(self, config, **kwargs)
def onConnect(self):
@ -147,7 +147,7 @@ class BuildComponent(BaseComponent):
LOGGER.debug('With Arguments: %s', build_arguments)
return (self.call("io.quay.builder.build", **build_arguments)
.add_done_callback(self._build_complete))
.add_done_callback(self._build_complete))
@staticmethod
def _total_completion(statuses, total_images):
@ -213,7 +213,9 @@ class BuildComponent(BaseComponent):
# Parse and update the phase and the status_dict. The status dictionary contains
# the pull/push progress, as well as the current step index.
with self._build_status as status_dict:
self._build_status.set_phase(phase)
if self._build_status.set_phase(phase):
LOGGER.debug('Build %s has entered a new phase: %s', self.builder_realm, phase)
BuildComponent._process_pushpull_status(status_dict, phase, docker_data, self._image_info)
# If the current message represents the beginning of a new step, then update the
@ -234,7 +236,7 @@ class BuildComponent(BaseComponent):
def _build_failure(self, error_message, exception=None):
""" Handles and logs a failed build. """
self._build_status.set_error(error_message, {
'internal_error': exception.message if exception else None
'internal_error': exception.message if exception else None
})
build_id = self._current_job.repo_build().uuid
@ -319,7 +321,7 @@ class BuildComponent(BaseComponent):
build_status = self._build_status
if build_status is not None:
with build_status as status_dict:
status_dict['heartbeat'] = int(datetime.time())
status_dict['heartbeat'] = int(time.time())
# Check the heartbeat from the worker.
LOGGER.debug('Checking heartbeat on realm %s', self.builder_realm)

View file

@ -34,12 +34,13 @@ class StatusHandler(object):
def set_phase(self, phase, extra_data=None):
if phase == self._current_phase:
return
return False
self._current_phase = phase
self._append_log_message(phase, self._build_logs.PHASE, extra_data)
self._repository_build.phase = phase
self._repository_build.save()
return True
def __enter__(self):
return self._status

View file

@ -154,7 +154,7 @@ class BuilderServer(object):
self._loop = loop
# Create the WAMP server.
transport_factory = WampWebSocketServerFactory(self._session_factory, debug_wamp=False)
transport_factory = WampWebSocketServerFactory(self._session_factory, debug_wamp=True)
transport_factory.setProtocolOptions(failByDrop=True)
# Initialize the controller server and the WAMP server
@ -162,4 +162,4 @@ class BuilderServer(object):
yield From(loop.create_server(transport_factory, host, 8080))
# Initialize the work queue checker.
yield self._work_checker()
yield From(self._work_checker())