-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathhook_rapid.py
More file actions
66 lines (51 loc) · 1.85 KB
/
hook_rapid.py
File metadata and controls
66 lines (51 loc) · 1.85 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
58
59
60
61
62
63
64
65
66
import pbs
import os
#default interactive
default_queue = "default"
interactive_queue = "interactive"
max_duration = pbs.duration("48:00:00")
allowed_hosts = ["ondemand.grid.cesnet.cz", "ondemand-dev.grid.cesnet.cz"]
def check_interactive_suitable(j, r):
if not j.interactive and not r in allowed_hosts:
return False
if j.Resource_List["walltime"] and pbs.duration(j.Resource_List["walltime"]) > max_duration:
return False
return True
def move_job(queue, jid):
os.environ["PBSPRO_IGNORE_KERBEROS"] = ""
os.environ['PATH'] += ":/opt/pbs/bin/"
os.system(str.format("qmove %s %s" % (queue, jid)))
try:
e = pbs.event()
if e.type == pbs.MODIFYJOB:
e.accept()
if e.type == pbs.QUEUEJOB:
j = e.job
requestor_host = e.requestor_host
# checking directly submited job suitability (in interactive queue)
if str(j.queue) == interactive_queue:
if check_interactive_suitable(j, requestor_host):
e.accept()
else:
e.reject("job is not suitable for the queue: %s" % str(interactive_queue))
# move suitable jobs to interactive queue
if str(j.queue) in ["", default_queue]:
if check_interactive_suitable(j, requestor_host):
if e.type == pbs.MODIFYJOB:
e.accept()
q = pbs.server().queue(interactive_queue)
j.queue = q
e.accept()
if e.type == pbs.PERIODIC:
q = pbs.server().queue(interactive_queue)
for j in q.jobs():
if j.job_state != pbs.JOB_STATE_QUEUED:
continue
if j.comment == None:
continue
move_job(default_queue, j.id)
e.accept()
except SystemExit:
pass
except Exception as err:
e.reject("rapid hook failed, error: %s" % str(err))