-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcheck_clearml_task_running.py
36 lines (31 loc) · 1.2 KB
/
check_clearml_task_running.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
import os
import sys
import time
from clearml import Task
def check_task_status(task_id, timeout):
"""Make sure the task can run by checking for iteration reports."""
# Get the task object
task = Task.get_task(task_id=task_id)
start_time = time.time()
if task:
while time.time() - start_time < timeout:
task_status = task.get_status()
print(task_status)
print(task.get_last_iteration())
if task_status == 'queued':
# If queued, just reset the timeout timer
start_time = time.time()
if task_status in ['failed', 'stopped']:
raise ValueError("Task did not run correctly, check logs in webUI.")
elif task_status == 'in_progress':
# Try to get the first iteration metric
if task.get_last_iteration() > 0:
task.mark_stopped()
task.set_archived(True)
return True
time.sleep(5)
raise ValueError('Triggered Timeout!')
else:
return f"Can not find task {task}.\n\n"
if __name__ == '__main__':
check_task_status(sys.argv[1], int(os.getenv('EXECUTION_TIMEOUT')))