closes #7399
[arvados.git] / services / crunch-dispatch-local / crunch-dispatch-local.go
index 47c3564502b4c5f27157102a93257386f2f1c96b..e05c0c5da4439e44931837ea5a259885624b80d8 100644 (file)
@@ -75,13 +75,8 @@ func doMain() error {
        runQueuedContainers(*pollInterval, *priorityPollInterval, *crunchRunCommand)
 
        // Finished dispatching; interrupt any crunch jobs that are still running
-       for uuid, cmd := range runningCmds {
-               go func(uuid string) {
-                       cmd.Process.Signal(os.Interrupt)
-                       if _, err := cmd.Process.Wait(); err != nil {
-                               log.Printf("Error while waiting for crunch job to finish for %v: %q", uuid, err)
-                       }
-               }(uuid)
+       for _, cmd := range runningCmds {
+               cmd.Process.Signal(os.Interrupt)
        }
 
        // Wait for all running crunch jobs to complete / terminate
@@ -181,22 +176,15 @@ func run(uuid string, crunchRunCommand string, priorityPollInterval int) {
        // A goroutine to terminate the runner if container priority becomes zero
        priorityTicker := time.NewTicker(time.Duration(priorityPollInterval) * time.Second)
        go func() {
-               for {
-                       select {
-                       case <-priorityTicker.C:
-                               var container Container
-                               err := arv.Get("containers", uuid, nil, &container)
-                               if err != nil {
-                                       log.Printf("Error getting container info for %v: %q", uuid, err)
-                               } else {
-                                       if container.Priority == 0 {
-                                               priorityTicker.Stop()
-                                               cmd.Process.Signal(os.Interrupt)
-                                               runningCmdsMutex.Lock()
-                                               delete(runningCmds, uuid)
-                                               runningCmdsMutex.Unlock()
-                                               return
-                                       }
+               for _ = range priorityTicker.C {
+                       var container Container
+                       err := arv.Get("containers", uuid, nil, &container)
+                       if err != nil {
+                               log.Printf("Error getting container info for %v: %q", uuid, err)
+                       } else {
+                               if container.Priority == 0 {
+                                       priorityTicker.Stop()
+                                       cmd.Process.Signal(os.Interrupt)
                                }
                        }
                }
@@ -227,4 +215,6 @@ func run(uuid string, crunchRunCommand string, priorityPollInterval int) {
                        log.Printf("Error updating container state to Complete for %v: %q", uuid, err)
                }
        }
+
+       log.Printf("Finished container run for %v", uuid)
 }