def trigger_refresh(): """Triggers refresh in the CCDH model.""" logger.info('Requesting refresh of CCDH Model.') token: str = get_settings().docker_user_token_limited if not token: logger.error( 'Error: Attempted to trigger update in CCDH Model repository, ' 'but "DOCKER_USER_TOKEN_LIMITED" was not found in environment.', file=sys.stderr) else: r = requests.post( 'https://api.github.com/repos/cancerDHC/ccdhmodel/dispatches', headers={ "Accept": "application/vnd.github.v3+json", "Content-Type": "application/json", "Authorization": "Bearer " + token }, json={"event_type": "refreshModel"}) if r.status_code >= 400: # errors defined as codes 400 and above logger.error( 'Error: Triggering update in CCDH Model repository failed.\n', 'Status code: ', r.status_code, '\n' 'Reason: ', r.reason, '\n' 'Response text: ', r.text, file=sys.stderr) else: logger.info('Success.')
async def startup(): """Start up FastAPI server""" settings = get_settings() app.state.graph = TccmGraph(settings) app.state.graph.connect() redis = aioredis.from_url(url=settings.redis_url, encoding="utf8", decode_responses=True) FastAPICache.init(backend=RedisBackend(redis), prefix="fastapi-cache")
def neo4j_graph(docker_ip, docker_services): settings = get_settings() port = docker_services.port_for('ccdh-neo4j', 7474) url = f'http://{docker_ip}:{port}' docker_services.wait_until_responsive(timeout=60.0, pause=0.1, check=lambda: is_responsive(url)) bolt_port = docker_services.port_for('ccdh-neo4j', 7687) bolt_url = f'bolt://{docker_ip}:{bolt_port}' graph = Graph(bolt_url, auth=(settings.neo4j_username, settings.neo4j_password)) yield graph
def read_ccdh_model_yaml(): """Read model yaml from CCDH Model GH repository""" branch = get_settings().ccdhmodel_branch yaml_url = f'https://raw.githubusercontent.com/cancerDHC/ccdhmodel/{branch}/model/schema/crdch_model.yaml' # to-do: Remove old yaml url when done w/ debugging: # Old yaml_url for debugging purposes (-jef 2021/11/19): # yaml_url = 'https://raw.githubusercontent.com/cancerDHC/ccdhmodel/253fdbc48f2d3df809f79356cbde6d449306e84f/model/schema/crdch_model.yaml' # 2021/09/23 logger.info("Retrieving CCDH Model YAML: " + yaml_url) r = requests.get(yaml_url) if r.status_code == 200: return r.content else: logger.info(f"Failed to Retrieving CCDH Model YAML: {r.status_code}") logger.info(r.content) raise ValueError('Failed to fetch yaml from ' + yaml_url)
"""Wrapper around the FastApiCache-2 library""" from fastapi_cache.decorator import cache from ccdh.config import get_settings # Note: args and kwargs left here because they are used by... # ...`fastapi_cache.decorator.cache` # noinspection PyUnusedLocal def nocache(*args, **kwargs): """Wrapper func""" def decorator(func): """Decorator""" return func return decorator if get_settings().environment_name == 'production': cache = cache else: cache = nocache
def test_config(): settings = get_settings() assert settings.neo4j_bolt_port is not None