Commit b9e33f40 authored by Mikhail Sennikov's avatar Mikhail Sennikov
Browse files

Fix warmup

parent 4c1f2531
No related merge requests found
Showing with 6 additions and 37 deletions
+6 -37
...@@ -66,10 +66,6 @@ class NodeSwarm: ...@@ -66,10 +66,6 @@ class NodeSwarm:
async with db.get_session() as session: async with db.get_session() as session:
group_repo = GroupRepository(session) group_repo = GroupRepository(session)
group = await group_repo.get(group_id) group = await group_repo.get(group_id)
if group is None:
raise HTTPException(
status_code=status.HTTP_404_NOT_FOUND
)
await self._set_group(group, session) await self._set_group(group, session)
return group return group
......
...@@ -18,21 +18,17 @@ hot_cams: HotCams = HotCams() ...@@ -18,21 +18,17 @@ hot_cams: HotCams = HotCams()
@node_router.post("/set/{node_id}", response_model=NodeFull) @node_router.post("/set/{node_id}", response_model=NodeFull)
async def set_node_id( async def set_node_id(
node_id: int, node_id: int,
node_repo: NodeRepository = Depends(db.get_repository(NodeRepository))
): ):
global current_node global current_node
global hot_cams global hot_cams
node = await node_repo.get(node_id) with db.get_session() as session:
if node is None: node_repo: NodeRepository = NodeRepository(session)
raise HTTPException( current_node = await node_repo.get(node_id)
status_code=status.HTTP_404_NOT_FOUND cams = await node_repo.get_node_cams(current_node)
)
current_node = node
# Warm up cams # Warm up cams
del hot_cams del hot_cams
hot_cams = HotCams() hot_cams = HotCams()
cams = await node_repo.get_node_cams(current_node)
cams = [int(getattr(cam, 'id')) for cam in cams] cams = [int(getattr(cam, 'id')) for cam in cams]
await hot_cams.try_connect_cams_list(cams) await hot_cams.try_connect_cams_list(cams)
return current_node return current_node
......
...@@ -23,6 +23,7 @@ class HotCams: ...@@ -23,6 +23,7 @@ class HotCams:
try: try:
cam = Camera(_cam_id, **kwargs) cam = Camera(_cam_id, **kwargs)
await cam.update() await cam.update()
print(f"Connection to camera {kwargs['name']} established.")
break break
except (ONVIFError, httpx.ConnectTimeout, httpx.ConnectError) as e: except (ONVIFError, httpx.ConnectTimeout, httpx.ConnectError) as e:
if 'name' in kwargs: if 'name' in kwargs:
...@@ -38,7 +39,7 @@ class HotCams: ...@@ -38,7 +39,7 @@ class HotCams:
async def try_connect(self, cam_id: int): async def try_connect(self, cam_id: int):
async with db.get_session() as session: async with db.get_session() as session:
cam_repo = CamRepository(session) cam_repo = CamRepository(session)
cam_db_obj = await cam_repo.get(cam_id) cam_db_obj = await cam_repo.get_or_none(cam_id)
if cam_db_obj is None: if cam_db_obj is None:
raise HTTPException( raise HTTPException(
status_code=status.HTTP_404_NOT_FOUND status_code=status.HTTP_404_NOT_FOUND
......
...@@ -30,10 +30,6 @@ async def get_group( ...@@ -30,10 +30,6 @@ async def get_group(
group_repo: GroupRepository = Depends(db.get_repository(GroupRepository)) group_repo: GroupRepository = Depends(db.get_repository(GroupRepository))
): ):
group = await group_repo.get(group_id) group = await group_repo.get(group_id)
if group is None:
raise HTTPException(
status_code=status.HTTP_404_NOT_FOUND
)
return group return group
...@@ -84,10 +80,6 @@ async def list_cams_in_group( ...@@ -84,10 +80,6 @@ async def list_cams_in_group(
group_repo: GroupRepository = Depends(db.get_repository(GroupRepository)) group_repo: GroupRepository = Depends(db.get_repository(GroupRepository))
): ):
group = await group_repo.get(group_id) group = await group_repo.get(group_id)
if group is None:
raise HTTPException(
status_code=status.HTTP_404_NOT_FOUND
)
return await group_repo.list_cams_in_group(group) return await group_repo.list_cams_in_group(group)
......
...@@ -30,10 +30,6 @@ async def get_cam( ...@@ -30,10 +30,6 @@ async def get_cam(
cam_repo: CamRepository = Depends(db.get_repository(CamRepository)) cam_repo: CamRepository = Depends(db.get_repository(CamRepository))
): ):
cam = await cam_repo.get(cam_id) cam = await cam_repo.get(cam_id)
if cam is None:
raise HTTPException(
status_code=status.HTTP_404_NOT_FOUND
)
return cam return cam
......
...@@ -27,10 +27,6 @@ async def get_node( ...@@ -27,10 +27,6 @@ async def get_node(
node_repo: NodeRepository = Depends(db.get_repository(NodeRepository)) node_repo: NodeRepository = Depends(db.get_repository(NodeRepository))
): ):
node = await node_repo.get(node_id) node = await node_repo.get(node_id)
if node is None:
raise HTTPException(
status_code=status.HTTP_404_NOT_FOUND
)
return node return node
......
...@@ -27,10 +27,6 @@ async def get_role( ...@@ -27,10 +27,6 @@ async def get_role(
role_repo: RoleRepository = Depends(db.get_repository(RoleRepository)) role_repo: RoleRepository = Depends(db.get_repository(RoleRepository))
): ):
role = await role_repo.get(role_id) role = await role_repo.get(role_id)
if role is None:
raise HTTPException(
status_code=status.HTTP_404_NOT_FOUND
)
return role return role
......
...@@ -29,10 +29,6 @@ async def get_user( ...@@ -29,10 +29,6 @@ async def get_user(
user_repo: UserRepository = Depends(db.get_repository(UserRepository)) user_repo: UserRepository = Depends(db.get_repository(UserRepository))
): ):
user = await user_repo.get(user_id) user = await user_repo.get(user_id)
if user is None:
raise HTTPException(
status_code=status.HTTP_404_NOT_FOUND
)
return user return user
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment