killer.py 465 Bytes
Newer Older
1
import sys
2
import balsam.launcher.dag as dag
3
4
5
6
7
8
9
10
import time

start = time.time()

while dag.BalsamJob.objects.filter(name="slow_job").count() == 0:
    time.sleep(2)
    if time.time() - start > 40:
        raise RuntimeError("the slow job never started")
11
12

slow_job = dag.BalsamJob.objects.get(name='slow_job')
13
14
15
16
17

if 'when-running' in ' '.join(sys.argv):
    while slow_job.state != 'RUNNING':
        time.sleep(2)
        slow_job.refresh_from_db()
18
dag.kill(slow_job)