def check_status(self, aoi_geojson: dict = None): try: client = self.get_service_client() response = client.check(aoi_geojson=aoi_geojson) except Exception as e: logger.error(e, exc_info=True) response = get_status_result(CheckResult.UNKNOWN_ERROR) logger.error(f"An exception occurred while checking the {self.name} provider.", exc_info=True) logger.info(f"Status of provider '{self.name}': {response}") return response
def check(self, aoi_geojson: Optional[dict] = None) -> dict: """ Main call to check the status of the service. Returns JSON with a status string and more detailed message. :param aoi: A geojson as a dict representing an AOI to check within the service instance. """ if aoi_geojson: self.set_aoi(aoi_geojson) # If the last check was successful assume checks will be successful for some period of time. status_check_cache_key = self.get_cache_key(aoi=self.aoi) try: status = cache.get(status_check_cache_key) if status: return status status = get_status_result(CheckResult.SUCCESS) # If the area is not valid, don't bother with a size. if not self.check_area(): raise ProviderCheckError(CheckResult.TOO_LARGE) # This response will rarely change, it will be information about the service. response = cache.get_or_set(self.get_cache_key(), lambda: self.check_response(), timeout=DEFAULT_CACHE_TIMEOUT) if not self.validate_response(response): raise ProviderCheckError(CheckResult.UNKNOWN_ERROR) cache.set(status_check_cache_key, status, timeout=DEFAULT_CACHE_TIMEOUT) return status except ProviderCheckError as pce: logger.error(pce, exc_info=True) # If checks fail throw that away so that we will check again on the next request. cache.delete(status_check_cache_key) cache.delete(self.get_cache_key()) return pce.status_result
def __init__(self, check_result: CheckResult = None, *args, **kwargs): if check_result: self.status_result = get_status_result(check_result=check_result, **kwargs) self.message = self.status_result["message"] super().__init__(*args)