Beispiel #1
0
def _wait_and_query(logs_dir, query, db_file_query_ready_timeout,
                    **kwargs) -> List[FireXTask]:
    with get_db_manager(logs_dir, read_only=True) as db_manager:
        wait_on_db_file_query_ready(logs_dir,
                                    db_manager=db_manager,
                                    timeout=db_file_query_ready_timeout)
        return db_manager.query_tasks(query, **kwargs)
Beispiel #2
0
def wait_on_keeper_complete(logs_dir, timeout=30) -> bool:
    # FIXME: subtract time spent waiting on query ready and schema before waiting on DB state.
    db_file_query_ready = wait_on_db_file_query_ready(logs_dir,
                                                      timeout=timeout)
    if not db_file_query_ready:
        return db_file_query_ready
    with get_db_manager(logs_dir, read_only=True) as db_manager:
        return wait_until(db_manager.is_keeper_complete,
                          timeout=timeout,
                          sleep_for=1)
Beispiel #3
0
def wait_on_db_file_query_ready(logs_dir, timeout=15, db_manager=None):
    db_file_exists = wait_until(os.path.isfile, timeout, 1,
                                get_db_file_path(logs_dir))
    if not db_file_exists:
        return db_file_exists

    if db_manager:
        return _wait_task_table_exist(db_manager, timeout)
    else:
        with get_db_manager(logs_dir, read_only=True) as db_manager:
            return _wait_task_table_exist(db_manager, timeout)
Beispiel #4
0
def task_tree(logs_dir, root_uuid=None, **kwargs) -> FireXTreeTask:
    with get_db_manager(logs_dir) as db_manager:
        if root_uuid is None:
            root_uuid = db_manager.query_single_run_metadata().root_uuid

        # TODO: could avoid fetching all tasks by using sqlite recursive query.
        all_tasks_by_uuid = {
            t.uuid: t
            for t in db_manager.query_tasks(True, **kwargs)
        }

    if root_uuid not in all_tasks_by_uuid:
        return None
    return _tasks_to_tree(root_uuid, all_tasks_by_uuid)
Beispiel #5
0
    def assert_expected_firex_output(self, cmd_output, cmd_err):
        logs_dir = get_log_dir_from_output(cmd_output)
        tasks = task_query.tasks_by_name(logs_dir, 'echo')
        assert tasks[0].name == 'echo'
        assert tasks[0].state == RunStates.SUCCEEDED.value

        firex_id = os.path.basename(logs_dir)
        with get_db_manager(logs_dir) as db_manager:
            run_metadata = db_manager.query_run_metadata(firex_id)
            is_complete = wait_until(db_manager.is_keeper_complete,
                                     timeout=5,
                                     sleep_for=0.5)
            assert is_complete is True

        assert run_metadata.chain == 'echo'
        assert run_metadata.firex_id == firex_id
        assert run_metadata.logs_dir == logs_dir

        all_uuids = {t.uuid for t in task_query.all_tasks(logs_dir)}
        assert run_metadata.root_uuid in all_uuids