Merge branch 'master' into 3219-further-docker-improvements
[arvados.git] / sdk / cli / bin / crunch-job
index ca2e8c49a5b66048c0918f8725a95c50f2365a86..30f06b8cab92bbd17689cd951d64d3f3abf0c148 100755 (executable)
@@ -82,6 +82,7 @@ use IPC::Open2;
 use IO::Select;
 use File::Temp;
 use Fcntl ':flock';
+use File::Path qw( make_path );
 
 $ENV{"TMPDIR"} ||= "/tmp";
 unless (defined $ENV{"CRUNCH_TMP"}) {
@@ -91,6 +92,12 @@ unless (defined $ENV{"CRUNCH_TMP"}) {
     $ENV{"CRUNCH_TMP"} .= "-$<";
   }
 }
+
+# Create the tmp directory if it does not exist
+if ( ! -d $ENV{"CRUNCH_TMP"} ) {
+  make_path $ENV{"CRUNCH_TMP"} or die "Failed to create temporary working directory: " . $ENV{"CRUNCH_TMP"};
+}
+
 $ENV{"JOB_WORK"} = $ENV{"CRUNCH_TMP"} . "/work";
 $ENV{"CRUNCH_INSTALL"} = "$ENV{CRUNCH_TMP}/opt";
 $ENV{"CRUNCH_WORK"} = $ENV{"JOB_WORK"}; # deprecated
@@ -661,15 +668,13 @@ for (my $todo_ptr = 0; $todo_ptr <= $#jobstep_todo; $todo_ptr ++)
           elsif ($env_key eq "TASK_KEEPMOUNT") {
             $command .= "--env=\QTASK_KEEPMOUNT=/keep\E ";
           }
-          elsif ($env_key eq "CRUNCH_SRC") {
-            $command .= "--env=\QCRUNCH_SRC=/tmp/crunch-src\E ";
-          }
           else {
             $command .= "--env=\Q$env_key=$env_val\E ";
           }
         }
       }
       $command .= "--env=\QCRUNCH_NODE_SLOTS=$ENV{CRUNCH_NODE_SLOTS}\E ";
+      $command .= "--env=\QCRUNCH_SRC=/tmp/crunch-src\E ";
       $command .= "\Q$docker_hash\E ";
       $command .= "stdbuf --output=0 --error=0 ";
       $command .= "/tmp/crunch-src/crunch_scripts/" . $Job->{"script"};
@@ -985,27 +990,29 @@ sub reapchildren
   push @freeslot, $proc{$pid}->{slot};
   delete $proc{$pid};
 
-  # Load new tasks
-  my $newtask_list = [];
-  my $newtask_results;
-  do {
-    $newtask_results = $arv->{'job_tasks'}->{'list'}->execute(
-      'where' => {
-        'created_by_job_task_uuid' => $Jobstep->{'arvados_task'}->{uuid}
-      },
-      'order' => 'qsequence',
-      'offset' => scalar(@$newtask_list),
-    );
-    push(@$newtask_list, @{$newtask_results->{items}});
-  } while (@{$newtask_results->{items}});
-  foreach my $arvados_task (@$newtask_list) {
-    my $jobstep = {
-      'level' => $arvados_task->{'sequence'},
-      'failures' => 0,
-      'arvados_task' => $arvados_task
-    };
-    push @jobstep, $jobstep;
-    push @jobstep_todo, $#jobstep;
+  if ($task_success) {
+    # Load new tasks
+    my $newtask_list = [];
+    my $newtask_results;
+    do {
+      $newtask_results = $arv->{'job_tasks'}->{'list'}->execute(
+        'where' => {
+          'created_by_job_task_uuid' => $Jobstep->{'arvados_task'}->{uuid}
+        },
+        'order' => 'qsequence',
+        'offset' => scalar(@$newtask_list),
+      );
+      push(@$newtask_list, @{$newtask_results->{items}});
+    } while (@{$newtask_results->{items}});
+    foreach my $arvados_task (@$newtask_list) {
+      my $jobstep = {
+        'level' => $arvados_task->{'sequence'},
+        'failures' => 0,
+        'arvados_task' => $arvados_task
+      };
+      push @jobstep, $jobstep;
+      push @jobstep_todo, $#jobstep;
+    }
   }
 
   $progress_is_dirty = 1;