-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathslurm_status.py
47 lines (33 loc) · 1.05 KB
/
slurm_status.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
37
38
39
40
41
42
43
44
45
#!/usr/bin/env python3
"""
Submit this clustering script for sbatch to snakemake with:
snakemake -j 99 --cluster slurm_scheduler.py --cluster-status slurm_status.py
"""
import os
import sys
import warnings
import subprocess
jobid = sys.argv[1]
out= subprocess.run(['scontrol','show','jobid',jobid],stdout=subprocess.PIPE).stdout.decode('utf-8')
def parse_key_value(stream):
params={}
for key_value_pair in stream.split():
name, var = key_value_pair.partition("=")[::2]
params[name.strip()] = var
return params
state=parse_key_value(out)['JobState']
map_state={"PENDING":'running',
"RUNNING":'running',
"SUSPENDED":'running',
"CANCELLED":'failed',
"COMPLETING":'running',
"COMPLETED":'success',
"CONFIGURING":'running',
"FAILED":'failed',
"TIMEOUT":'failed',
"PREEMPTED":'failed',
"NODE_FAIL":'failed',
"REVOKED":'failed',
"SPECIAL_EXIT":'failed',
"":'success'}
print(map_state[state])