Пример #1
0
def wait_for_timescale(max_wait: float = 10.0, sleep_interval: float = 0.5):
    time_left_to_wait = max_wait
    while time_left_to_wait > 0:
        try:
            with postgres_translator_instance():
                return
        except BaseException:
            time_left_to_wait -= sleep_interval
            sleep(sleep_interval)
    assert False, f"waited longer than {max_wait} secs for timescale!"
Пример #2
0
def check_db(db=CRATE_BACKEND):
    """
    crateDB is the default backend of QuantumLeap, so it is required by
    default.
    """
    if db == CRATE_BACKEND:
        from translators.crate import crate_translator_instance
        with crate_translator_instance() as trans:
            health = trans.get_health()
            return health
    if db == TIMESCALE_BACKEND:
        from translators.timescale import postgres_translator_instance
        with postgres_translator_instance() as trans:
            health = trans.get_health()
            return health
def translator_for(fiware_service: str):
    backend = backend_id_for(fiware_service)

    if backend == CRATE_BACKEND:
        translator = crate_translator_instance()
        selected = CRATE_BACKEND
    elif backend == TIMESCALE_BACKEND:
        translator = postgres_translator_instance()
        selected = TIMESCALE_BACKEND
    else:
        translator = crate_translator_instance()
        selected = CRATE_BACKEND

    log().debug(
        f"Backend selected for tenant '{fiware_service}' is: {selected}")
    return translator
Пример #4
0
def translator_for(fiware_service: str):
    backend = lookup_backend(fiware_service)
    backend = backend.strip().lower() if backend is not None else ''

    if backend == CRATE_BACKEND:
        translator = CrateTranslatorInstance()
        selected = CRATE_BACKEND
    elif backend == TIMESCALE_BACKEND:
        translator = postgres_translator_instance()
        selected = TIMESCALE_BACKEND
    else:
        translator = CrateTranslatorInstance()
        selected = CRATE_BACKEND

    log().info(
        f"Backend selected for tenant '{fiware_service}' is: {selected}")
    return translator
Пример #5
0
def translator_for(fiware_service: str):
    reader = YamlReader(log=log().debug)
    config = reader.from_env_file(QL_CONFIG_ENV_VAR, defaults={})

    backend = maybe_string_match(config, 'tenants', fiware_service, 'backend')\
        or maybe_string_match(config, 'default-backend')
    backend = backend.strip().lower() if backend is not None else ''

    if backend == CRATE_BACKEND:
        translator = CrateTranslatorInstance()
        selected = CRATE_BACKEND
    elif backend == TIMESCALE_BACKEND:
        translator = postgres_translator_instance()
        selected = TIMESCALE_BACKEND
    else:
        translator = CrateTranslatorInstance()
        selected = CRATE_BACKEND

    log().info(
        f"Backend selected for tenant '{fiware_service}' is: {selected}")
    return translator
def insert(entities, fw_svc=None, fw_path=None):
    with postgres_translator_instance() as trans:
        trans.insert(entities, fw_svc, fw_path)