def __build_from_live_server(self, repository): """Implements CommandProcessor interface.""" docs_url_path = SWAGGER_URL_PATHS[repository.name] env = dict(os.environ) port = unused_port() env['SERVER_PORT'] = str(port) base_url = 'http://localhost:' + str(port) gate_logfile = self.get_logfile_path(repository.name + '-apidocs-server') logging.info( 'Starting up prototype %s so we can extract docs from it.' ' We will log this instance to %s', repository.name, gate_logfile) boot_run_cmd = './gradlew' # default will run ensure_dir_exists(os.path.dirname(gate_logfile)) gate_logstream = open(gate_logfile, 'w') process = start_subprocess(boot_run_cmd, stream=gate_logstream, stdout=gate_logstream, cwd=repository.git_dir, env=env) max_wait_secs = self.options.max_wait_secs_startup # pylint: disable=broad-except try: logging.info('Waiting up to %s secs for %s to be ready on port %d', max_wait_secs, repository.name, port) self.wait_for_url(base_url + '/health', max_wait_secs) json_path = os.path.join(self.get_output_dir(), 'docs.json') self.__generate_json_from_url(repository, base_url + '/' + docs_url_path, json_path) self.build_swagger_docs(repository, json_path) finally: try: gate_logstream.flush() gate_logstream.write( '\n' + log_timestring() + ' ***** buildtool is killing subprocess *****\n') logging.info( 'Killing %s subprocess %s now that we are done with it', repository.name, process.pid) process.kill() wait_subprocess(process) gate_logstream.close() except Exception as ex: maybe_log_exception( self.name, ex, 'Ignoring exception while stopping {name} subprocess {pid}.' .format(name=repository.name, pid=process.pid))
def __build_from_live_server(self, repository): """Implements CommandProcessor interface.""" docs_url_path = SWAGGER_URL_PATHS[repository.name] env = dict(os.environ) port = unused_port() env['SERVER_PORT'] = str(port) base_url = 'http://localhost:' + str(port) gate_logfile = self.get_logfile_path(repository.name + '-apidocs-server') logging.info('Starting up prototype %s so we can extract docs from it.' ' We will log this instance to %s', repository.name, gate_logfile) boot_run_cmd = './gradlew' # default will run ensure_dir_exists(os.path.dirname(gate_logfile)) gate_logstream = open(gate_logfile, 'w') process = start_subprocess( boot_run_cmd, stream=gate_logstream, stdout=gate_logstream, cwd=repository.git_dir, env=env) max_wait_secs = self.options.max_wait_secs_startup # pylint: disable=broad-except try: logging.info('Waiting up to %s secs for %s to be ready on port %d', max_wait_secs, repository.name, port) self.wait_for_url(base_url + '/health', max_wait_secs) json_path = os.path.join(self.get_output_dir(), 'docs.json') self.__generate_json_from_url( repository, base_url + '/' + docs_url_path, json_path) self.build_swagger_docs(repository, json_path) finally: try: gate_logstream.flush() gate_logstream.write( '\n' + log_timestring() + ' ***** buildtool is killing subprocess *****\n') logging.info('Killing %s subprocess %s now that we are done with it', repository.name, process.pid) process.kill() wait_subprocess(process) gate_logstream.close() except Exception as ex: maybe_log_exception( self.name, ex, 'Ignoring exception while stopping {name} subprocess {pid}.' .format(name=repository.name, pid=process.pid))