Skip to content

Commit 2527af2

Browse files
Jeny Sadadiamgalka
authored andcommitted
api.models: Add 'wait_for_node' method
Add method to Node model to wait got node to get completed until specified timeout. Signed-off-by: Jeny Sadadia <[email protected]>
1 parent 387659f commit 2527af2

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

api/models.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
"""KernelCI API model definitions"""
88

9+
import asyncio
910
from datetime import datetime, timedelta
1011
from typing import Optional, Dict
1112
import enum
@@ -197,3 +198,11 @@ def set_timeout_status(self):
197198
self.status = "timeout"
198199
return True
199200
return False
201+
202+
@classmethod
203+
async def wait_for_node(cls, timeout):
204+
"""Wait for node to get completed until timeout"""
205+
current_time = datetime.utcnow()
206+
if timeout > current_time:
207+
time_delta = timeout - current_time
208+
await asyncio.sleep(time_delta.total_seconds())

0 commit comments

Comments
 (0)