fix sub R1 R2
[arvados.git] / crunch_scripts / run-command
index 528baab4c18c8f0ea23360719c36b6a1605c9f2e..6335523a74a01b8e22a4b3021a971d9732f640d1 100755 (executable)
@@ -50,24 +50,41 @@ try:
         stdoutname = subst.do_substitution(p, p["stdout"])
         stdoutfile = open(stdoutname, "wb")
 
-    print("Running command: {}{}".format(' '.join(cmd), (" > " + stdoutname) if stdoutname != None else ""))
+    print("run-command: {}{}".format(' '.join(cmd), (" > " + stdoutname) if stdoutname != None else ""))
 
     rcode = subprocess.call(cmd, stdout=stdoutfile)
 
+    print("run-command: completed with exit code %i" % rcode)
+
 except Exception as e:
-    print("Caught exception {}".format(e))
+    print("run-command: caught exception: {}".format(e))
 
 finally:
     for l in links:
         os.unlink(l)
 
+    print("run-command: the follow output files will be saved to keep:")
+
+    subprocess.call(["find", ".", "-type", "f", "-printf", "run-command: %12.12s %h/%f\\n"])
+
+    print("run-command: start writing output to keep")
+
     out = arvados.CollectionWriter()
     out.write_directory_tree(".", max_manifest_depth=0)
-    arvados.current_task().set_output(out.finish())
+    outuuid = out.finish()
+    arvados.api('v1').job_tasks().update(uuid=arvados.current_task()['uuid'],
+                                         body={
+                                             'output':outuuid,
+                                             'success': (rcode == 0),
+                                             'progress':1.0
+                                         }).execute()
 
 if rcode == 0:
     os.chdir("..")
     shutil.rmtree("tmpdir")
     shutil.rmtree("output")
+    print("run-command: success")
+else:
+    print("run-command: failed")
 
 sys.exit(rcode)