Fixed background task not stopping on detach
Some checks failed
checks-impure / test (pull_request) Successful in 30s
checks / test (pull_request) Failing after 1m42s

This commit is contained in:
2024-01-08 19:33:29 +01:00
parent 1cb81473c3
commit 5f4eb1f521
19 changed files with 389 additions and 420 deletions

View File

@@ -64,7 +64,9 @@ def get_services_without_entity_id(
# #
#########################
def create_entity(db: Session, entity: schemas.EntityCreate) -> sql_models.Entity:
db_entity = sql_models.Entity(**entity.dict(), attached=False, stop_health_task=False)
db_entity = sql_models.Entity(
**entity.dict(), attached=False, stop_health_task=False
)
db.add(db_entity)
db.commit()
db.refresh(db_entity)
@@ -100,14 +102,12 @@ def get_attached_entities(
# Returns same entity if setting didnt changed something
def stop_entity_health_task(
db: Session, entity_did: str
) -> None:
def set_stop_health_task(db: Session, entity_did: str, value: bool) -> None:
db_entity = get_entity_by_did(db, entity_did)
if db_entity is None:
raise ClanError(f"Entity with did '{entity_did}' not found")
setattr(db_entity, "stop_health_task", True)
setattr(db_entity, "stop_health_task", value)
# save changes in db
db.add(db_entity)
@@ -115,10 +115,7 @@ def stop_entity_health_task(
db.refresh(db_entity)
def set_attached_by_entity_did(
db: Session, entity_did: str, attached: bool
) -> None:
def set_attached_by_entity_did(db: Session, entity_did: str, attached: bool) -> None:
db_entity = get_entity_by_did(db, entity_did)
if db_entity is None:
raise ClanError(f"Entity with did '{entity_did}' not found")