Skip to content

Commit 322b2e7

Browse files
Jeny Sadadiagctucker
Jeny Sadadia
authored andcommitted
api: remove Node.set_timeout_status and trigger completed endpoint
Need to remove Node method to set node status to timeout as we will have a client script for it. Need to remove 'trigger_completed_event' endpoint as we can use 'updated' event to mark node as completed and use it to generate test report. Fixes: 2e3c506 ("api.main: Add 'trigger_completed_event' endpoint") Signed-off-by: Jeny Sadadia <[email protected]>
1 parent e51ca85 commit 322b2e7

File tree

2 files changed

+1
-61
lines changed

2 files changed

+1
-61
lines changed

api/main.py

-50
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,8 @@
88

99
"""KernelCI API main module"""
1010

11-
from datetime import timedelta
1211
from typing import List, Union
1312
from fastapi import Depends, FastAPI, HTTPException, status, Request, Security
14-
from fastapi.encoders import jsonable_encoder
1513
from fastapi.security import (
1614
OAuth2PasswordRequestForm,
1715
SecurityScopes
@@ -207,54 +205,6 @@ async def get_root_node(node_id: str):
207205
return node
208206

209207

210-
@app.get('/trigger_completed_event/{node_id}')
211-
async def trigger_completed_event(node_id: str, wait_time_hours: int = 0,
212-
wait_time_minutes: int = 0,
213-
wait_time_seconds: int = 0):
214-
"""Trigger an event when all child nodes are completed of
215-
a given node"""
216-
try:
217-
nodes = await db.find_by_attributes(Node,
218-
{"parent": ObjectId(node_id)})
219-
220-
except errors.InvalidId as error:
221-
raise HTTPException(
222-
status_code=status.HTTP_400_BAD_REQUEST,
223-
detail=str(error)
224-
) from error
225-
226-
if not nodes:
227-
raise HTTPException(
228-
status_code=status.HTTP_400_BAD_REQUEST,
229-
detail=f"No child node found of a given node id:{node_id}"
230-
)
231-
232-
for node in nodes:
233-
if node.status == 'pending':
234-
timeout = node.created + timedelta(hours=wait_time_hours,
235-
minutes=wait_time_minutes,
236-
seconds=wait_time_seconds)
237-
await Node.wait_for_node(timeout)
238-
239-
ret = node.set_timeout_status()
240-
if ret:
241-
try:
242-
await db.update(node)
243-
except ValueError as error:
244-
raise HTTPException(
245-
status_code=status.HTTP_400_BAD_REQUEST,
246-
detail=str(error)
247-
) from error
248-
else:
249-
return {"message": "Nodes are not completed yet"}
250-
251-
operation = 'completed'
252-
await pubsub.publish_cloudevent('node', {'op': operation,
253-
'id': str(node_id),
254-
'nodes': jsonable_encoder(nodes)})
255-
return {"message": "'Event triggered"}
256-
257-
258208
@app.post('/node', response_model=Node)
259209
async def post_node(node: Node, token: str = Depends(get_user)):
260210
"""Create a new node"""

api/models.py

+1-11
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
"""KernelCI API model definitions"""
88

99
import asyncio
10-
from datetime import datetime, timedelta
10+
from datetime import datetime
1111
from typing import Optional, Dict, List
1212
import enum
1313
from bson import ObjectId, errors
@@ -226,16 +226,6 @@ def translate_fields(cls, params: dict):
226226
translated['parent'] = ObjectId(parent)
227227
return translated
228228

229-
def set_timeout_status(self):
230-
"""Set Node status to timeout if maximum wait time is over"""
231-
if self.status == "pending":
232-
current_time = datetime.utcnow()
233-
max_wait_time = self.created + timedelta(hours=self.max_wait_time)
234-
if current_time > max_wait_time:
235-
self.status = "timeout"
236-
return True
237-
return False
238-
239229
@classmethod
240230
async def wait_for_node(cls, timeout):
241231
"""Wait for node to get completed until timeout"""

0 commit comments

Comments
 (0)