2014-12-22 17:14:16 +00:00
|
|
|
from trollius import coroutine
|
|
|
|
|
2014-11-11 23:23:15 +00:00
|
|
|
class BaseManager(object):
|
|
|
|
""" Base for all worker managers. """
|
2014-11-21 19:27:06 +00:00
|
|
|
def __init__(self, register_component, unregister_component, job_heartbeat_callback,
|
2014-12-31 16:33:56 +00:00
|
|
|
job_complete_callback, manager_hostname, heartbeat_period_sec):
|
2014-11-11 23:23:15 +00:00
|
|
|
self.register_component = register_component
|
|
|
|
self.unregister_component = unregister_component
|
2014-11-21 19:27:06 +00:00
|
|
|
self.job_heartbeat_callback = job_heartbeat_callback
|
2014-11-11 23:23:15 +00:00
|
|
|
self.job_complete_callback = job_complete_callback
|
2014-12-31 16:33:56 +00:00
|
|
|
self.manager_hostname = manager_hostname
|
2014-12-22 22:24:44 +00:00
|
|
|
self.heartbeat_period_sec = heartbeat_period_sec
|
2014-11-11 23:23:15 +00:00
|
|
|
|
2014-12-22 22:24:44 +00:00
|
|
|
@coroutine
|
2014-11-21 19:27:06 +00:00
|
|
|
def job_heartbeat(self, build_job):
|
|
|
|
""" Method invoked to tell the manager that a job is still running. This method will be called
|
|
|
|
every few minutes. """
|
|
|
|
self.job_heartbeat_callback(build_job)
|
|
|
|
|
|
|
|
def setup_time(self):
|
|
|
|
""" Returns the number of seconds that the build system should wait before allowing the job
|
|
|
|
to be picked up again after called 'schedule'.
|
|
|
|
"""
|
|
|
|
raise NotImplementedError
|
|
|
|
|
2014-11-11 23:23:15 +00:00
|
|
|
def shutdown(self):
|
|
|
|
""" Indicates that the build controller server is in a shutdown state and that no new jobs
|
|
|
|
or workers should be performed. Existing workers should be cleaned up once their jobs
|
|
|
|
have completed
|
|
|
|
"""
|
|
|
|
raise NotImplementedError
|
|
|
|
|
2014-12-22 17:14:16 +00:00
|
|
|
@coroutine
|
2014-12-31 16:33:56 +00:00
|
|
|
def schedule(self, build_job):
|
2015-06-10 18:17:32 +00:00
|
|
|
""" Schedules a queue item to be built. Returns a 2-tuple with (True, None) if the item was
|
|
|
|
properly scheduled and (False, a retry timeout in seconds) if all workers are busy or an
|
|
|
|
error occurs.
|
2014-11-11 23:23:15 +00:00
|
|
|
"""
|
|
|
|
raise NotImplementedError
|
|
|
|
|
2014-12-16 18:41:30 +00:00
|
|
|
def initialize(self, manager_config):
|
2014-11-11 23:23:15 +00:00
|
|
|
""" Runs any initialization code for the manager. Called once the server is in a ready state.
|
|
|
|
"""
|
|
|
|
raise NotImplementedError
|
|
|
|
|
2014-12-31 16:33:56 +00:00
|
|
|
@coroutine
|
|
|
|
def build_component_ready(self, build_component):
|
2014-12-16 18:41:30 +00:00
|
|
|
""" Method invoked whenever a build component announces itself as ready.
|
|
|
|
"""
|
|
|
|
raise NotImplementedError
|
|
|
|
|
2014-11-11 23:23:15 +00:00
|
|
|
def build_component_disposed(self, build_component, timed_out):
|
|
|
|
""" Method invoked whenever a build component has been disposed. The timed_out boolean indicates
|
|
|
|
whether the component's heartbeat timed out.
|
|
|
|
"""
|
|
|
|
raise NotImplementedError
|
|
|
|
|
2014-12-22 17:14:16 +00:00
|
|
|
@coroutine
|
2014-11-12 19:03:07 +00:00
|
|
|
def job_completed(self, build_job, job_status, build_component):
|
2014-11-11 23:23:15 +00:00
|
|
|
""" Method invoked once a job_item has completed, in some manner. The job_status will be
|
2014-12-22 17:14:16 +00:00
|
|
|
one of: incomplete, error, complete. Implementations of this method should call
|
|
|
|
self.job_complete_callback with a status of Incomplete if they wish for the job to be
|
|
|
|
automatically requeued.
|
2014-11-11 23:23:15 +00:00
|
|
|
"""
|
2014-11-18 20:45:56 +00:00
|
|
|
raise NotImplementedError
|
2014-12-16 18:37:40 +00:00
|
|
|
|
|
|
|
def num_workers(self):
|
|
|
|
""" Returns the number of active build workers currently registered. This includes those
|
|
|
|
that are currently busy and awaiting more work.
|
|
|
|
"""
|
|
|
|
raise NotImplementedError
|