+{% codeblock as python %}
+import arvados.collection
+import json
+cwl_container_request = arv_client.container_requests().get(
+ uuid='zzzzz-xvhdp-12345abcde67890',
+).execute()
+cwl_output_collection = arvados.collection.Collection(
+ cwl_container_request['output_uuid'],
+)
+with cwl_output_collection.open('cwl.output.json') as cwl_output_file:
+ cwl_output = json.load(cwl_output_file)
+... # Work with the cwl_output dictionary
+{% endcodeblock %}
+
+h3(#get-log-of-a-child-request). Get logs of a container or CWL workflow run
+
+A container's log files are saved in a collection. The UUID of that collection is recorded in the @log_uuid@ of the container request, which you can load as you like.
+
+{% codeblock as python %}
+import arvados.collection
+container_request = arv_client.container_requests().get(
+ uuid='zzzzz-xvhdp-12345abcde67890',
+).execute()
+log_collection = arvados.collection.Collection(
+ container_request['log_uuid'],
+)
+# From here, you can process the container's log collection any way you like.
+# Below is an example that writes the container's stderr to this process' stderr.
+import shutil
+import sys
+with log_collection.open('stderr.txt') as containter_stderr:
+ shutil.copyfileobj(container_stderr, sys.stderr)
+{% endcodeblock %}
+
+h3(#get-state-of-a-cwl-workflow). Get status of a container or CWL workflow run
+
+Workbench shows users a single status badge for container requests. This status is synthesized from different fields on the container request and associated container. This code shows how to do analogous reporting using the Python SDK.
+
+{% codeblock as python %}
+container_request = arv_client.container_requests().get(
+ uuid='zzzzz-xvhdp-12345abcde67890',
+).execute()
+if container_request['container_uuid'] is None:
+ status = container_request['state']
+else:
+ container = arv_client.containers().get(
+ uuid=container_request['container_uuid'],
+ ).execute()
+ container_state = container['state']
+ if container_state == 'Queued' or container_state == 'Locked':
+ status = "On hold" if container['priority'] == 0 else "Queued"
+ elif container_state == 'Running':
+ if container['runtime_status'].get('error'):
+ status = "Failing"
+ elif container['runtime_status'].get('warning'):
+ status = "Warning"
+ else:
+ status = container_state
+ elif container_state == 'Cancelled':
+ status = container_state
+ elif container_state == 'Complete':
+ status = "Completed" if container['exit_code'] == 0 else "Failed"
+... # Report status as desired
+{% endcodeblock %}
+
+h3(#list-failed-child-requests). List child requests of a container or CWL workflow run
+
+When a running container creates a container request to do additional work, the UUID of the source container is recorded in the @requesting_container_uuid@ field of the new container request. You can list container requests with this filter to find requests created by a specific container.
+
+{% codeblock as python %}
+import arvados.util
+for child_container_requests in arvados.util.keyset_list_all(
+ # Pass the method keyset_list_all will call to retrieve items.
+ # Do not call it yourself.
+ arv_client.container_requests().list,
+ filters=[
+ # Note this is a container UUID, *not* a container request UUID
+ ['requesting_container_uuid', '=', 'zzzzz-dz642-12345abcde67890'],
+ # You may add other filters for your listing.
+ # For example, you could filter by 'name' to find specific kinds
+ # of steps of a CWL workflow.
+ ...,
+ ],
+):
+ ... # Work with each child container request