First implementation of ephemeral build lifecycle manager.

This commit is contained in:
Jake Moshenko 2014-12-16 13:41:30 -05:00
parent 79b61e7709
commit 2d7e844753
10 changed files with 453 additions and 56 deletions

View file

@ -28,10 +28,12 @@ class DynamicRegistrationComponent(BaseComponent):
class EnterpriseManager(BaseManager):
""" Build manager implementation for the Enterprise Registry. """
build_components = []
shutting_down = False
def initialize(self):
def __init__(self, *args, **kwargs):
self.ready_components = set()
self.shutting_down = False
def initialize(self, manager_config):
# Add a component which is used by build workers for dynamic registration. Unlike
# production, build workers in enterprise are long-lived and register dynamically.
self.register_component(REGISTRATION_REALM, DynamicRegistrationComponent)
@ -45,21 +47,20 @@ class EnterpriseManager(BaseManager):
""" Adds a new build component for an Enterprise Registry. """
# Generate a new unique realm ID for the build worker.
realm = str(uuid.uuid4())
component = self.register_component(realm, BuildComponent, token="")
self.build_components.append(component)
self.register_component(realm, BuildComponent, token="")
return realm
def schedule(self, build_job, loop):
""" Schedules a build for an Enterprise Registry. """
if self.shutting_down:
if self.shutting_down or not self.ready_components:
return False
for component in self.build_components:
if component.is_ready():
loop.call_soon(component.start_build, build_job)
return True
component = self.ready_components.pop()
loop.call_soon(component.start_build, build_job)
return True
return False
def build_component_ready(self, build_component, loop):
self.ready_components.add(build_component)
def shutdown(self):
self.shutting_down = True
@ -68,5 +69,6 @@ class EnterpriseManager(BaseManager):
self.job_complete_callback(build_job, job_status)
def build_component_disposed(self, build_component, timed_out):
self.build_components.remove(build_component)
if build_component in self.ready_components:
self.ready_components.remove(build_component)