|
8 | 8 |
|
9 | 9 | """KernelCI API main module"""
|
10 | 10 |
|
11 |
| -from datetime import timedelta |
12 | 11 | from typing import List, Union
|
13 | 12 | from fastapi import Depends, FastAPI, HTTPException, status, Request, Security
|
14 |
| -from fastapi.encoders import jsonable_encoder |
15 | 13 | from fastapi.security import (
|
16 | 14 | OAuth2PasswordRequestForm,
|
17 | 15 | SecurityScopes
|
@@ -207,54 +205,6 @@ async def get_root_node(node_id: str):
|
207 | 205 | return node
|
208 | 206 |
|
209 | 207 |
|
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 |
| - |
258 | 208 | @app.post('/node', response_model=Node)
|
259 | 209 | async def post_node(node: Node, token: str = Depends(get_user)):
|
260 | 210 | """Create a new node"""
|
|
0 commit comments