class PipelineServer(ManagedService): """ Thin wrapper around PipelineServer constructs. Allows controlled start and stop of the web app server in a separate process. Parameters ---------- config : yaml reference to the yaml configuration file """ def __init__(self, config): self.config = config self.pipeline_server_job = None self._restarting = threading.Event() def trigger_event(self, event: config_mgm.ConfigChangedEvent): """Trigger change event on pipelines not running. Pipelines already runnig are already notified by rective configurations """ if self.pipeline_server_job is None: return if self._restarting.is_set(): return self._restarting.set() self.stop() self.start() self._restarting.clear() def start(self, **kwargs): log.info('PipelineServer server job starting...') f = PipelineServerJob(self.config) self.pipeline_server_job = ThreadedJob(f) self.pipeline_server_job.start() log.info('Pipeline server job started') def healthcheck(self): return time.monotonic(), True def heal(self): """Heal the server. TODO: Keep an eye for potential scenarios that cause this server to become unresponsive. """ def stop(self): if self.pipeline_server_job: log.info('Pipeline server job stopping...') self.pipeline_server_job.stop() self.pipeline_server_job.join() self.pipeline_server_job = None log.info('Pipeline server job stopped.')
class PipelineServer(ManagedService): """Thin wrapper around PipelineServer constructs. Allows controlled start and stop of the web app server in a separate process. Parameters ---------- config : yaml reference to the yaml configuration file """ def __init__(self, config): self.config = config self.pipeline_server_job = None def start(self, **kwargs): log.info("PipelineServer server job starting...") f = PipelineServerJob(self.config) self.pipeline_server_job = ThreadedJob(f) self.pipeline_server_job.start() log.info("Pipeline server job started") def healthcheck(self): return time.monotonic(), True def heal(self): """Heal the server. TODO: Keep an eye for potential scenarios that cause this server to become unresponsive. """ def stop(self): if self.pipeline_server_job: log.info("Pipeline server job stopping...") try: self.pipeline_server_job.stop() self.pipeline_server_job.join() except RuntimeError as err: log.warning("Failed stopping: %s" % err) self.pipeline_server_job = None log.info("Pipeline server job stopped.")
class FlaskServer(ManagedService): """ Thin wrapper around Flask constructs. Allows controlled start and stop of the web app server in a separate process. Parameters ---------- config : yaml reference to the yaml configuration file """ def __init__(self, config): self.config = config self.flask_job = None def start(self, **kwargs): log.info('Flask server job starting...') f = FlaskJob(self.config) self.flask_job = ThreadedJob(f) self.flask_job.start() log.info('Flask server job started') def healthcheck(self): # Note: Implement actual health check for Flask # See if the /healthcheck URL returns a 200 quickly return time.monotonic(), True def heal(self): """Heal the server. TODO: Keep an eye for potential scenarios that cause this server to become unresponsive. """ def stop(self): if self.flask_job: log.info('Flask server job stopping...') self.flask_job.stop() self.flask_job.join() log.info('Flask server job stopped.')