Skip to content

Commit 7706bfc

Browse files
authored
Allow submission when all running jobs are in CG state (#332)
1 parent d5b0a70 commit 7706bfc

File tree

2 files changed

+88
-3
lines changed

2 files changed

+88
-3
lines changed

babs/interaction.py

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,17 @@ def babs_submit(self, count=None, submit_df=None, skip_failed=False):
3333
# Check if there are still jobs running
3434
currently_running_df = self.get_currently_running_jobs_df()
3535
if currently_running_df.shape[0] > 0:
36-
raise Exception(
37-
'There are still jobs running. Please wait for them to finish or cancel them.'
38-
f' Current running jobs:\n{currently_running_df}'
36+
non_cg_states = (
37+
currently_running_df['state'].fillna('').ne('CG')
38+
if 'state' in currently_running_df
39+
else np.array([True] * currently_running_df.shape[0])
3940
)
41+
if non_cg_states.any():
42+
raise Exception(
43+
'There are still jobs running. Please wait for them to finish or cancel them.'
44+
f' Current running jobs:\n{currently_running_df}'
45+
)
46+
print('All currently running jobs are in CG state; proceeding with submission.')
4047

4148
# Find the rows that don't have results yet
4249
status_df = self.get_job_status_df()

tests/test_interaction.py

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
"""Tests for interaction behaviors."""
2+
3+
import pandas as pd
4+
import pytest
5+
6+
from babs.interaction import BABSInteraction
7+
8+
9+
def _minimal_status_df():
10+
return pd.DataFrame(
11+
{
12+
'sub_id': ['sub-01', 'sub-02'],
13+
'submitted': [False, False],
14+
'has_results': [False, False],
15+
'is_failed': [False, False],
16+
'job_id': [-1, -1],
17+
'task_id': [-1, -1],
18+
'state': ['', ''],
19+
'time_used': ['', ''],
20+
'time_limit': ['', ''],
21+
'nodes': [0, 0],
22+
'cpus': [0, 0],
23+
'partition': ['', ''],
24+
'name': ['', ''],
25+
}
26+
)
27+
28+
29+
def test_babs_submit_blocks_non_cg_jobs(babs_project_subjectlevel, monkeypatch):
30+
babs_proj = BABSInteraction(project_root=babs_project_subjectlevel)
31+
running_df = pd.DataFrame(
32+
{
33+
'job_id': [1],
34+
'task_id': [1],
35+
'state': ['R'],
36+
'time_used': ['0:01'],
37+
'time_limit': ['5-00:00:00'],
38+
'nodes': [1],
39+
'cpus': [1],
40+
'partition': ['normal'],
41+
'name': ['test_array_job'],
42+
}
43+
)
44+
monkeypatch.setattr(babs_proj, 'get_currently_running_jobs_df', lambda: running_df)
45+
46+
with pytest.raises(Exception, match='There are still jobs running'):
47+
babs_proj.babs_submit(count=1)
48+
49+
50+
def test_babs_submit_allows_cg_jobs(babs_project_subjectlevel, monkeypatch):
51+
babs_proj = BABSInteraction(project_root=babs_project_subjectlevel)
52+
running_df = pd.DataFrame(
53+
{
54+
'job_id': [1],
55+
'task_id': [1],
56+
'state': ['CG'],
57+
'time_used': ['0:01'],
58+
'time_limit': ['5-00:00:00'],
59+
'nodes': [1],
60+
'cpus': [1],
61+
'partition': ['normal'],
62+
'name': ['test_array_job'],
63+
}
64+
)
65+
monkeypatch.setattr(babs_proj, 'get_currently_running_jobs_df', lambda: running_df)
66+
monkeypatch.setattr(babs_proj, 'get_job_status_df', _minimal_status_df)
67+
68+
submit_calls = []
69+
70+
def _mock_submit_array(analysis_path, queue, total_jobs):
71+
submit_calls.append((analysis_path, queue, total_jobs))
72+
return 123
73+
74+
monkeypatch.setattr('babs.interaction.submit_array', _mock_submit_array)
75+
76+
babs_proj.babs_submit(count=1)
77+
78+
assert submit_calls

0 commit comments

Comments
 (0)