15350: Adds PySDK recipe to get a container request's state.
authorLucas Di Pentima <ldipentima@veritasgenetics.com>
Tue, 11 Jun 2019 16:55:34 +0000 (13:55 -0300)
committerLucas Di Pentima <ldipentima@veritasgenetics.com>
Tue, 11 Jun 2019 16:55:34 +0000 (13:55 -0300)
Arvados-DCO-1.1-Signed-off-by: Lucas Di Pentima <ldipentima@veritasgenetics.com>

doc/sdk/python/cookbook.html.textile.liquid

index c8ac5d1036ffb1b2939617895537bde9d8eba3de..1c0f4500d3f97585fc8bee0afdc162b81f731817 100644 (file)
@@ -64,6 +64,40 @@ collection = arvados.collection.CollectionReader(container_request["output_uuid"
 print(collection.open("cwl.output.json").read())
 {% endcodeblock %}
 
+h2. Get state of a CWL workflow
+
+{% codeblock as python %}
+import arvados
+def get_cr_state(cr_uuid):
+    api = arvados.api()
+    cr = api.container_requests().get(uuid=cr_uuid).execute()
+    if cr['container_uuid'] is None:
+        return cr['state']
+    c = api.containers().get(uuid=cr['container_uuid']).execute()
+    if cr['state'] == 'Final' and c['state'] != 'Complete':
+        return 'Cancelled'
+    elif c['state'] in ['Locked', 'Queued']:
+        if c['priority'] == 0:
+            return 'On hold'
+        else:
+            return 'Queued'
+    elif c['state'] == 'Complete':
+        if c['exit_code'] == 0:
+            return c['state']
+        else:
+            return 'Failed'
+    elif c['state'] == 'Running':
+        if c['runtime_status'].get('error', None):
+            return 'Failing'
+        elif c['runtime_status'].get('warning', None):
+            return 'Warning'
+        else:
+            return c['state']
+    return c['state']
+container_request_uuid = 'qr1hi-xvhdp-zzzzzzzzzzzzzzz'
+print(get_cr_state(container_request_uuid))
+{% endcodeblock %}
+
 h2. List input of child requests
 
 {% codeblock as python %}