Skip to content

Commit

Permalink
Merge pull request #34 from broadinstitute/se-add-workflow-hold-param
Browse files Browse the repository at this point in the history
Add on_hold param to start_workflow
  • Loading branch information
samanehsan authored May 31, 2018
2 parents 49e50a8 + 72f2ac9 commit bac0044
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 5 deletions.
6 changes: 4 additions & 2 deletions cromwell_tools/cromwell_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ def wait_until_workflow_completes(
@retry(reraise=True, wait=wait_exponential(multiplier=1, max=10), stop=stop_after_delay(20))
def start_workflow(
wdl_file, inputs_file, url, options_file=None, inputs_file2=None, zip_file=None, user=None,
password=None, caas_key=None, collection_name=None, label=None, validate_labels=True):
password=None, caas_key=None, collection_name=None, label=None, validate_labels=True, on_hold=False):
"""
Use HTTP POST to start workflow in Cromwell and retry with exponentially increasing wait times between requests
if there are any failures. View statistics about the retries with `start_workflow.retry.statistics`.
Expand All @@ -156,7 +156,8 @@ def start_workflow(
:param str collection_name: (optional) collection in SAM that the workflow should belong to.
:param str|_io.BytesIO label: (optional) JSON file containing a collection of key/value pairs for workflow labels.
:param bool validate_labels: (optional) Whether to validate labels or not, using cromwell-tools' built-in
validators. It is set to True by default.
validators. It is set to True by default.
:param bool on_hold: (optional) Whether to submit the workflow in "On Hold" status.
:return requests.Response response: HTTP response from cromwell.
"""
Expand All @@ -166,6 +167,7 @@ def start_workflow(
files = {
'workflowSource': wdl_file,
'workflowInputs': inputs_file,
'workflowOnHold': json.dumps(on_hold)
}

if inputs_file2 is not None:
Expand Down
2 changes: 2 additions & 0 deletions cromwell_tools/scripts/cromwell-tools
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ def _start_workflow(arguments):
url=arguments.cromwell_url + '/api/workflows/v1',
user=user,
password=password,
on_hold=arguments.on_hold
)
response.raise_for_status() # determine if workflow succeeded
print(response.json()['id'])
Expand Down Expand Up @@ -111,6 +112,7 @@ if __name__ == '__main__':
run.add_argument('--inputs-json', type=str, required=True)
run.add_argument('--inputs2-json', type=str)
run.add_argument('--options-file', type=str)
run.add_argument('--on-hold', type=str)

# wait arguments
wait.add_argument('--workflow-ids', nargs='+', required=True)
Expand Down
7 changes: 4 additions & 3 deletions cromwell_tools/tests/test_cromwell_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ def setUp(self):
self.inputs_file2 = io.BytesIO(b"inputs_file2_content")
self.options_file = io.BytesIO(b"options_file_content")
self.label = io.BytesIO(b'{"test-label-key": "test-label-value"}')
self.on_hold = False
self.url = "https://fake_url"
self.user = "fake_user"
self.password = "fake_password"
Expand All @@ -65,7 +66,7 @@ def _request_callback(request, context):
mock_request.post(self.url, json=_request_callback)
result = cromwell_tools.start_workflow(
self.wdl_file, self.inputs_file, self.url, self.options_file, self.inputs_file2, self.zip_file, self.user,
self.password, label=self.label)
self.password, label=self.label, on_hold=self.on_hold)
self.assertEqual(result.status_code, 200)
self.assertEqual(result.headers.get('test'), 'header')

Expand All @@ -84,7 +85,7 @@ def _request_callback(request, context):
with self.assertRaises(requests.HTTPError):
result = cromwell_tools.start_workflow(
self.wdl_file, self.inputs_file, self.url, self.options_file, self.inputs_file2, self.zip_file,
self.user, self.password, label=self.label)
self.user, self.password, label=self.label, on_hold=self.on_hold)
self.assertNotEqual(mock_request.call_count, 1)

# Reset default retry value
Expand All @@ -103,7 +104,7 @@ def _request_callback(request, context):
mock_request.post(self.url, json=_request_callback)
result = cromwell_tools.start_workflow(
self.wdl_file, self.inputs_file, self.url, self.options_file, self.inputs_file2, self.zip_file,
caas_key=self.caas_key, label=self.label)
caas_key=self.caas_key, label=self.label, on_hold=self.on_hold)
self.assertEqual(result.status_code, 200)
self.assertEqual(result.headers.get('test'), 'header')

Expand Down

0 comments on commit bac0044

Please sign in to comment.