Merge branch '11807-yaml-to-json'
[arvados.git] / services / crunch-dispatch-local / crunch-dispatch-local.go
index bb3c05c7eb88b9abed4ff8278ff3fbdfcf367be8..888a2148c1797aa330167d6ca4b44c6a914e5000 100644 (file)
@@ -1,12 +1,14 @@
+// Copyright (C) The Arvados Authors. All rights reserved.
+//
+// SPDX-License-Identifier: AGPL-3.0
+
 package main
 
 // Dispatcher service for Crunch that runs containers locally.
 
 import (
+       "context"
        "flag"
-       "git.curoverse.com/arvados.git/sdk/go/arvados"
-       "git.curoverse.com/arvados.git/sdk/go/arvadosclient"
-       "git.curoverse.com/arvados.git/sdk/go/dispatch"
        "log"
        "os"
        "os/exec"
@@ -14,6 +16,10 @@ import (
        "sync"
        "syscall"
        "time"
+
+       "git.curoverse.com/arvados.git/sdk/go/arvados"
+       "git.curoverse.com/arvados.git/sdk/go/arvadosclient"
+       "git.curoverse.com/arvados.git/sdk/go/dispatch"
 )
 
 func main() {
@@ -61,7 +67,8 @@ func doMain() error {
                PollPeriod:   time.Duration(*pollInterval) * time.Second,
        }
 
-       err = dispatcher.Run()
+       ctx, cancel := context.WithCancel(context.Background())
+       err = dispatcher.Run(ctx)
        if err != nil {
                return err
        }
@@ -72,7 +79,7 @@ func doMain() error {
        log.Printf("Received %s, shutting down", sig)
        signal.Stop(c)
 
-       dispatcher.Stop()
+       cancel()
 
        runningCmdsMutex.Lock()
        // Finished dispatching; interrupt any crunch jobs that are still running
@@ -103,7 +110,7 @@ var startCmd = startFunc
 // crunch-run terminates, mark the container as Cancelled.
 func run(dispatcher *dispatch.Dispatcher,
        container arvados.Container,
-       status chan arvados.Container) {
+       status <-chan arvados.Container) {
 
        uuid := container.UUID
 
@@ -170,8 +177,7 @@ func run(dispatcher *dispatch.Dispatcher,
        if err != nil {
                log.Printf("Error getting final container state: %v", err)
        }
-       if container.LockedByUUID == dispatcher.Auth.UUID &&
-               (container.State == dispatch.Locked || container.State == dispatch.Running) {
+       if container.State == dispatch.Locked || container.State == dispatch.Running {
                log.Printf("After %s process termination, container state for %v is %q.  Updating it to %q",
                        *crunchRunCommand, container.State, uuid, dispatch.Cancelled)
                dispatcher.UpdateState(uuid, dispatch.Cancelled)