def check(request: pyramid.request.Request) -> None: path = request.route_path("printproxy_report_create", format="pdf") url_headers = build_url("Check the printproxy request (create)", path, request) session = requests.session() resp = session.post(json=print_settings["spec"], timeout=30, **url_headers) # type: ignore resp.raise_for_status() job = resp.json() path = request.route_path("printproxy_status", ref=job["ref"]) url_headers = build_url("Check the printproxy pdf status", path, request) done = False while not done: sleep(1) resp = session.get(timeout=30, **url_headers) # type: ignore resp.raise_for_status() status = resp.json() if "error" in status: raise Exception( f"Failed to do the printing: {status['error']}") done = status["done"] path = request.route_path("printproxy_report_get", ref=job["ref"]) url_headers = build_url("Check the printproxy pdf retrieve", path, request) resp = session.get(timeout=30, **url_headers) # type: ignore resp.raise_for_status()
def __call__(self, request: pyramid.request.Request) -> None: path = request.route_path(self.route["name"], _query=self.route.get("params", {})) url: str = cast(str, build_url("Check", path, request)["url"]) cmd: List[str] = ["node", "/usr/bin/check-example.js", url] env = dict(os.environ) for name, value in self.route.get("environment", {}).items(): if isinstance(value, (list, dict)): value = json.dumps(value) elif not isinstance(value, str): value = str(value) env[name] = value try: subprocess.check_output(cmd, env=env, timeout=70) except subprocess.CalledProcessError as exception: raise Exception( f"{' '.join(exception.cmd)} exit with code: {exception.returncode}\n" f"{exception.output.decode('utf-8')[:10000]}" ) from exception except subprocess.TimeoutExpired as exception: raise Exception(f"""Timeout: command: {' '.join(exception.cmd)} output: {exception.output.decode('utf-8')}""") from exception
def check(request: pyramid.request.Request) -> None: path = request.route_path("themes") session = requests.session() for (interface, ) in DBSession.query(Interface.name).all(): params: Dict[str, str] = {} params.update(default_params) params.update( interfaces_settings.get(interface, {}).get("params", {})) params["interface"] = interface interface_url_headers = build_url("checker_themes " + interface, path, request) response = session.get(params=params, timeout=120, **interface_url_headers) # type: ignore response.raise_for_status() result = response.json() if result["errors"]: raise c2cwsgiutils.health_check.JsonCheckException( f"Interface '{interface}' has error in Theme.", result["errors"])
def __call__( self, request: pyramid.request.Request ) -> Union[str, Dict[str, str]]: return build_url("route", request.route_path(self.route_name), request)[self.type]
def get_both( request: pyramid.request.Request ) -> Dict[str, Union[str, Dict[str, str]]]: return build_url("Check the fulltextsearch", request.route_path("fulltextsearch"), request)