Skip to content

Commit a240f7c

Browse files
committed
add remap option to rerun_invocation() method
1 parent a13ce01 commit a240f7c

File tree

2 files changed

+38
-1
lines changed

2 files changed

+38
-1
lines changed

bioblend/_tests/TestGalaxyInvocations.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,24 @@ def test_rerun_invocation(self):
145145
history = self.gi.histories.show_history(rerun_invocation['history_id'], contents=True)
146146
self.assertEqual(len(history), 3)
147147

148+
@test_util.skip_unless_galaxy('release_21.05')
149+
def test_rerun_and_remap_invocation(self):
150+
path = test_util.get_abspath(os.path.join('data', 'select_first.ga'))
151+
wf = self.gi.workflows.import_workflow_from_local_path(path)
152+
wf_inputs = {
153+
"0": {'src': 'hda', 'id': self.dataset_id},
154+
"1": "-1",
155+
}
156+
invocation_id = self.gi.workflows.invoke_workflow(wf['id'], inputs=wf_inputs, history_id=self.history_id)['id']
157+
errored_jobs = self.gi.jobs.get_jobs(state='error', invocation_id=invocation_id)
158+
self.assertEqual(len(errored_jobs), 1)
159+
self.gi.invocations.rerun_invocation(invocation_id, remap=True)
160+
last_dataset = self.gi.datasets.get_datasets(history_id=self.history_id)[-1]
161+
self.gi.datasets.wait_for_dataset(last_dataset['id'])
162+
new_errored_jobs = self.gi.jobs.get_jobs(state='error', invocation_id=invocation_id)
163+
self.assertEqual(len(new_errored_jobs), 1)
164+
self.assertNotEqual(errored_jobs[0]['id'], new_errored_jobs[0]['id'])
165+
148166
def _invoke_workflow(self):
149167
dataset = {'src': 'hda', 'id': self.dataset_id}
150168

bioblend/galaxy/invocations/__init__.py

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ def show_invocation(self, invocation_id):
132132
url = self._make_url(invocation_id)
133133
return self._get(url=url)
134134

135-
def rerun_invocation(self, invocation_id: str, inputs_update: Optional[dict] = None,
135+
def rerun_invocation(self, invocation_id: str, remap: bool = False, inputs_update: Optional[dict] = None,
136136
params_update: Optional[dict] = None, history_id: Optional[str] = None,
137137
history_name: Optional[str] = None, import_inputs_to_history: bool = False,
138138
replacement_params: Optional[dict] = None, allow_tool_state_corrections: bool = False,
@@ -144,6 +144,13 @@ def rerun_invocation(self, invocation_id: str, inputs_update: Optional[dict] = N
144144
:type invocation_id: str
145145
:param invocation_id: Encoded workflow invocation ID to be rerun
146146
147+
:type remap: bool
148+
:param remap: when ``True``, only failed jobs will be rerun. All other parameters
149+
for this method will be ignored. Job output(s) will be remapped onto the dataset(s)
150+
created by the original jobs; if other jobs were waiting for these jobs to finish
151+
successfully, they will be resumed using the new outputs of the tool runs. When ``False``,
152+
an entire new invocation will be created, using the other parameters specified.
153+
147154
:type inputs_update: dict
148155
:param inputs_update: If different datasets should be used to the original
149156
invocation, this should contain a mapping of workflow inputs to the new
@@ -196,6 +203,18 @@ def rerun_invocation(self, invocation_id: str, inputs_update: Optional[dict] = N
196203
.. note::
197204
This method can only be used with Galaxy ``release_21.01`` or later.
198205
"""
206+
if remap:
207+
errored_jobs = self.gi.jobs.get_jobs(state='error', invocation_id=invocation_id)
208+
remap_failures = 0
209+
for job in errored_jobs:
210+
try:
211+
self.gi.jobs.rerun_job(job['id'], remap=True)
212+
except ValueError:
213+
remap_failures += 1
214+
if remap_failures:
215+
raise ValueError(f'remap was set to True, but {remap_failures} out of {len(errored_jobs)} errored jobs could not be remapped.')
216+
return None
217+
199218
invocation_details = self.show_invocation(invocation_id)
200219
workflow_id = invocation_details['workflow_id']
201220
inputs = invocation_details['inputs']

0 commit comments

Comments
 (0)