added attach with background task
All checks were successful
checks-impure / test (pull_request) Successful in 30s
checks / test (pull_request) Successful in 3m18s

This commit is contained in:
Georg-Stahn
2023-12-03 16:56:16 +01:00
parent 09d0c28fd6
commit 9a31fbe010
3 changed files with 57 additions and 15 deletions

View File

@@ -1,3 +1,4 @@
import time
from typing import List, Optional
from sqlalchemy.orm import Session
@@ -136,3 +137,21 @@ def get_entities(
def get_entity_by_did(db: Session, did: str) -> Optional[sql_models.Entity]:
return db.query(sql_models.Entity).filter(sql_models.Entity.did == did).first()
def check_health(db: Session, entity_did: str, message: str) -> str:
# ste attached to true
db_entity = get_entity_by_did(db, entity_did)
if db_entity is not None:
# db_entity.attached = Column(True)
setattr(db_entity, "attached", True)
# save changes in db
db.add(db_entity)
db.commit()
db.refresh(db_entity)
# check every 5 secounds if status has changed
while db_entity.attached:
time.sleep(5)
return f"{entity_did} message"
else:
return f"{entity_did} not found and not attached"