X-Git-Url: https://git.arvados.org/arvados.git/blobdiff_plain/f9e3d32c92920a806d50548dbb9b6c0aab7d8c54..0eb72b526bf8bbb011551ecf019f604e17a534f1:/services/crunch-dispatch-local/crunch-dispatch-local.go diff --git a/services/crunch-dispatch-local/crunch-dispatch-local.go b/services/crunch-dispatch-local/crunch-dispatch-local.go index 0ca7651851..888a2148c1 100644 --- a/services/crunch-dispatch-local/crunch-dispatch-local.go +++ b/services/crunch-dispatch-local/crunch-dispatch-local.go @@ -1,17 +1,25 @@ +// 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" + "os/signal" "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() { @@ -54,16 +62,25 @@ func doMain() error { arv.Retries = 25 dispatcher := dispatch.Dispatcher{ - Arv: arv, - RunContainer: run, - PollInterval: time.Duration(*pollInterval) * time.Second, - DoneProcessing: make(chan struct{})} + Arv: arv, + RunContainer: run, + PollPeriod: time.Duration(*pollInterval) * time.Second, + } - err = dispatcher.RunDispatcher() + ctx, cancel := context.WithCancel(context.Background()) + err = dispatcher.Run(ctx) if err != nil { return err } + c := make(chan os.Signal, 1) + signal.Notify(c, os.Interrupt, syscall.SIGTERM, syscall.SIGQUIT) + sig := <-c + log.Printf("Received %s, shutting down", sig) + signal.Stop(c) + + cancel() + runningCmdsMutex.Lock() // Finished dispatching; interrupt any crunch jobs that are still running for _, cmd := range runningCmds { @@ -93,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 @@ -160,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)