forked from NIH-HPC/snakemake_profile
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbw_status.py
More file actions
executable file
·57 lines (52 loc) · 1.13 KB
/
bw_status.py
File metadata and controls
executable file
·57 lines (52 loc) · 1.13 KB
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#! /usr/local/bin/python3
import subprocess
import sys
import time
jobid = sys.argv[-1]
# the dashboard data has some delay, so if dashboard_cli returns
# a non-zero exit code retry 4 times with 11s delays
attempts = 0
state = None
while attempts < 4:
attempts += 1
res = subprocess.run(
[
"dashboard_cli",
"jobs",
"-j",
jobid,
"--fields",
"state",
"--since",
"-10d",
"--noheader",
],
capture_output=True,
encoding="ascii",
)
if res.returncode == 0:
state = res.stdout.strip()
break
if res.returncode == 4:
# the job is not yet known to dashboard_cli. Assume 'running'
state = "RUNNING"
break
if attempts == 4:
print(res.stderr)
sys.exit(res.returncode)
else:
time.sleep(11)
running_status = [
"PENDING",
"CONFIGURING",
"COMPLETING",
"RUNNING",
"SUSPENDED",
"PREEMPTED",
]
if state == "COMPLETED":
print("success")
elif state in running_status:
print("running")
else:
print("failed")