async def query_user_from_db(aiopg_engine: aiopg.sa.Engine, user: Dict):
    """returns a user from the db"""
    async with aiopg_engine.acquire() as conn:
        user_result = await conn.execute(
            users.select().where(users.c.id == int(user["id"]))
        )
        return await user_result.first()
async def assert_projects_count(
    aiopg_engine: aiopg.sa.Engine, expected_projects: int
) -> bool:
    async with aiopg_engine.acquire() as conn:
        projects_count = await conn.scalar(select(func.count()).select_from(projects))
        assert projects_count == expected_projects
        return True
async def change_user_role(
    aiopg_engine: aiopg.sa.Engine, user: Dict, role: UserRole
) -> None:
    async with aiopg_engine.acquire() as conn:
        await conn.execute(
            users.update().where(users.c.id == int(user["id"])).values(role=role.value)
        )
Exemple #4
0
async def assert_projects_count(
    db_engine: aiopg.sa.Engine, expected_projects: int
) -> True:
    async with db_engine.acquire() as conn:
        projects_count = await conn.scalar(projects.count())
        assert projects_count == expected_projects
        return True
Exemple #5
0
async def query_project_from_db(aiopg_engine: aiopg.sa.Engine,
                                project_uuid: str) -> Dict[str, Any]:
    async with aiopg_engine.acquire() as conn:
        project_result = await conn.execute(
            projects.select().where(projects.c.uuid == project_uuid))
        project = await project_result.first()
        assert project is not None
        return dict(project)
async def query_project_from_db(db_engine: aiopg.sa.Engine,
                                user_project: Dict):
    async with db_engine.acquire() as conn:
        project_result = await conn.execute(
            projects.select().where(projects.c.uuid == user_project["uuid"]))
        return await project_result.first()
async def assert_users_count(db_engine: aiopg.sa.Engine,
                             expected_users: int) -> True:
    async with db_engine.acquire() as conn:
        users_count = await conn.scalar(users.count())
        assert users_count == expected_users
        return True
Exemple #8
0
async def inspect(
    # pylint: disable=too-many-arguments
    db_engine: aiopg.sa.Engine,
    rabbit_mq: RabbitMQ,
    job_request_id: int,
    user_id: str,
    project_id: str,
    node_id: str,
) -> Optional[List[str]]:
    log.debug(
        "ENTERING inspect with user %s pipeline:node %s: %s",
        user_id,
        project_id,
        node_id,
    )

    pipeline: aiopg.sa.result.RowProxy = None
    task: aiopg.sa.result.RowProxy = None
    graph: nx.DiGraph = None
    async with db_engine.acquire() as connection:
        pipeline = await _get_pipeline_from_db(connection, project_id)
        graph = execution_graph(pipeline)
        if not node_id:
            log.debug("NODE id was zero, this was the entry node id")
            return find_entry_point(graph)
        task = await _try_get_task_from_db(connection, graph, job_request_id,
                                           project_id, node_id)

    if not task:
        log.debug("no task at hand, let's rest...")
        return

    # config nodeports
    node_ports.node_config.USER_ID = user_id
    node_ports.node_config.NODE_UUID = task.node_id
    node_ports.node_config.PROJECT_ID = task.project_id

    # now proceed actually running the task (we do that after the db session has been closed)
    # try to run the task, return empyt list of next nodes if anything goes wrong
    run_result = SUCCESS
    next_task_nodes = []
    try:
        sidecar = Executor(
            db_engine=db_engine,
            rabbit_mq=rabbit_mq,
            task=task,
            user_id=user_id,
        )
        await sidecar.run()
        next_task_nodes = list(graph.successors(node_id))
    except exceptions.SidecarException:
        run_result = FAILED
        log.exception("Error during execution")

    finally:
        async with db_engine.acquire() as connection:
            await connection.execute(
                # FIXME: E1120:No value for argument 'dml' in method call
                # pylint: disable=E1120
                comp_tasks.update().where(
                    and_(
                        comp_tasks.c.node_id == node_id,
                        comp_tasks.c.project_id == project_id,
                    )).values(state=run_result, end=datetime.utcnow()))

    return next_task_nodes