diff --git a/pkgs/clan-cli/clan_cli/webui/routers/sql_connect.py b/pkgs/clan-cli/clan_cli/webui/routers/sql_connect.py index 6ca4093..35ed6ac 100644 --- a/pkgs/clan-cli/clan_cli/webui/routers/sql_connect.py +++ b/pkgs/clan-cli/clan_cli/webui/routers/sql_connect.py @@ -1,7 +1,8 @@ import time from typing import List, Optional -from fastapi import APIRouter, BackgroundTasks, Depends, Request +from httpx import AsyncClient +from fastapi import APIRouter, BackgroundTasks, Depends from sqlalchemy.orm import Session from .. import sql_crud, sql_db, sql_models @@ -112,7 +113,7 @@ def create_repository( response_model=List[Repository], tags=[Tags.repositories], ) -def get_repositories(get +def get_repositories( skip: int = 0, limit: int = 100, db: Session = Depends(sql_db.get_db) ) -> List[sql_models.Repository]: repositories = sql_crud.get_repositories(db, skip=skip, limit=limit) @@ -203,12 +204,13 @@ async def attach( return {"message": "Attaching in the background"} # TODO -def attach_entity(entity_did: str, db: Session) -> None: +async def attach_entity(entity_did: str, db: Session) -> None: db_entity = sql_crud.set_attached_by_entity_did(db, entity_did, True) try: while db_entity.attached: #query status endpoint - subprocess.run(f'curl http://{db_entity.ip}') + async with AsyncClient(app=app, base_url=f"http://{db_entity.ip}") as ac: + response = await ac.get("/") # test with: while true; do { echo -e 'HTTP/1.1 200 OK\r\n'; echo 'test'; } | nc -l 5556; done #except not reached set false time.sleep(1) diff --git a/pkgs/clan-cli/clan_cli/webui/sql_crud.py b/pkgs/clan-cli/clan_cli/webui/sql_crud.py index 0e22ac9..e86743b 100644 --- a/pkgs/clan-cli/clan_cli/webui/sql_crud.py +++ b/pkgs/clan-cli/clan_cli/webui/sql_crud.py @@ -142,7 +142,7 @@ def get_entity_by_did(db: Session, did: str) -> Optional[sql_models.Entity]: def get_attached_entities( db: Session, skip: int = 0, limit: int = 100 ) -> List[sql_models.Entity]: - return db.query(sql_models.Entity).offset(skip).limit(limit).filter(sql_models.Entity.attached == True) + return db.query(sql_models.Entity).offset(skip).limit(limit).filter(sql_models.Entity.attached is True) # set attached