georgs5 #31

Merged
Ghost merged 11 commits from georgs5 into main 2023-12-04 21:22:22 +00:00
2 changed files with 7 additions and 5 deletions
Showing only changes of commit 086966918a - Show all commits

View File

@@ -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 '<html>test</html>'; } | nc -l 5556; done
#except not reached set false
time.sleep(1)

View File

@@ -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