def post_process(self): """ Post-process executors """ exc_info = exc_value = None for executor in self.executors: self.log.debug("Post-process %s", executor) try: executor.post_process() if executor in self.started_modules and not executor.has_results( ): msg = "Empty results, most likely %s (%s) failed. " \ "Actual reason for this can be found in logs under %s" message = msg % (executor.label, executor.__class__.__name__, self.engine.artifacts_dir) diagnostics = executor.get_error_diagnostics() raise ToolError(message, diagnostics) except BaseException as exc: msg = "Exception in post_process of %s: %s %s" self.log.debug(msg, executor.__class__.__name__, exc, traceback.format_exc()) if not exc_info: exc_info = sys.exc_info() if not exc_value: exc_value = exc if exc_info: reraise(exc_info, exc_value)
def _shutdown(self): """ Shutdown modules :return: """ self.log.info("Shutting down...") self.log.debug("Current stop reason: %s", self.stopping_reason) if self.graceful_tmp and not os.path.exists(self.graceful_tmp): open(self.graceful_tmp, 'x').close() exc_info = exc_value = None modules = [self.provisioning, self.aggregator ] + self.reporters + self.services # order matters for module in modules: try: if module in self.started: module.shutdown() except BaseException as exc: self.log.debug("%s:\n%s", exc, traceback.format_exc()) if not self.stopping_reason: self.stopping_reason = exc if not exc_value: exc_value = exc exc_info = sys.exc_info() if self.graceful_tmp and os.path.exists(self.graceful_tmp): os.remove(self.graceful_tmp) self.config.dump() if exc_value: reraise(exc_info, exc_value)
def post_process(self): """ Do post-run analysis and processing for the results. """ self.log.info("Post-processing...") # :type exception: BaseException exc_info = exc_value = None modules = [self.provisioning, self.aggregator ] + self.reporters + self.services # order matters # services are last because of shellexec which is "final-final" action for module in modules: if module in self.prepared: try: module.post_process() except BaseException as exc: if isinstance(exc, KeyboardInterrupt): self.log.debug("post_process: %s", exc) else: self.log.debug("post_process: %s\n%s", exc, traceback.format_exc()) if not self.stopping_reason: self.stopping_reason = exc if not exc_value: exc_value = exc exc_info = sys.exc_info() self.config.dump() if exc_info: reraise(exc_info, exc_value)
def run(self): """ Run the job. Calls `startup`, does periodic `check`, calls `shutdown` in any case """ self.log.info("Starting...") exc_info = exc_value = None try: self._startup() self.logging_level_down() self._wait() except BaseException as exc: self.log.debug("%s:\n%s", exc, traceback.format_exc()) if not self.stopping_reason: self.stopping_reason = exc exc_value = exc exc_info = sys.exc_info() finally: self.log.warning("Please wait for graceful shutdown...") try: self.logging_level_up() self._shutdown() except BaseException as exc: self.log.debug("%s:\n%s", exc, traceback.format_exc()) if not self.stopping_reason: self.stopping_reason = exc if not exc_value: exc_value = exc exc_info = sys.exc_info() if exc_value: reraise(exc_info, exc_value)
def shutdown(self): """ Call shutdown on executors """ exc_info = exc_value = None for executor in self.started_modules: self.log.debug("Shutdown %s", executor) try: executor.shutdown() except BaseException as exc: msg = "Exception in shutdown of %s: %s %s" self.log.debug(msg, executor.__class__.__name__, exc, traceback.format_exc()) if not exc_info: exc_info = sys.exc_info() if not exc_value: exc_value = exc if exc_info: reraise(exc_info, exc_value)