X-Git-Url: https://git.arvados.org/arvados.git/blobdiff_plain/67afdf7bd1d53164e91e38e3b3a801ae83da778d..0821f5481edd016a3744bb50d97a9e5b99cd1a0f:/sdk/go/dispatch/dispatch.go diff --git a/sdk/go/dispatch/dispatch.go b/sdk/go/dispatch/dispatch.go index 53f41d29d0..4987c01055 100644 --- a/sdk/go/dispatch/dispatch.go +++ b/sdk/go/dispatch/dispatch.go @@ -25,7 +25,7 @@ const ( // Dispatcher holds the state of the dispatcher type Dispatcher struct { // The Arvados client - Arv arvadosclient.ArvadosClient + Arv *arvadosclient.ArvadosClient // When a new queued container appears and is either already owned by // this dispatcher or is successfully locked, the dispatcher will call @@ -178,7 +178,7 @@ func (dispatcher *Dispatcher) handleUpdate(container arvados.Container) { if container.State == Queued && container.Priority > 0 { // Try to take the lock - if err := dispatcher.UpdateState(container.UUID, Locked); err != nil { + if err := dispatcher.Lock(container.UUID); err != nil { return } container.State = Locked @@ -193,21 +193,6 @@ func (dispatcher *Dispatcher) handleUpdate(container arvados.Container) { // UpdateState makes an API call to change the state of a container. func (dispatcher *Dispatcher) UpdateState(uuid string, newState arvados.ContainerState) error { - if newState == Locked { - err := dispatcher.Arv.Call("POST", "containers", uuid, "lock", nil, nil) - if err != nil { - log.Printf("Error locking container %s: %q", uuid, err) - } - return err - } else if newState == Queued { - err := dispatcher.Arv.Call("POST", "containers", uuid, "unlock", nil, nil) - if err != nil { - log.Printf("Error unlocking container %s: %q", uuid, err) - } - return err - } - - // All other states err := dispatcher.Arv.Update("containers", uuid, arvadosclient.Dict{ "container": arvadosclient.Dict{"state": newState}}, @@ -218,6 +203,24 @@ func (dispatcher *Dispatcher) UpdateState(uuid string, newState arvados.Containe return err } +// Lock makes the lock API call which updates the state of a container to Locked. +func (dispatcher *Dispatcher) Lock(uuid string) error { + err := dispatcher.Arv.Call("POST", "containers", uuid, "lock", nil, nil) + if err != nil { + log.Printf("Error locking container %s: %q", uuid, err) + } + return err +} + +// Unlock makes the unlock API call which updates the state of a container to Queued. +func (dispatcher *Dispatcher) Unlock(uuid string) error { + err := dispatcher.Arv.Call("POST", "containers", uuid, "unlock", nil, nil) + if err != nil { + log.Printf("Error unlocking container %s: %q", uuid, err) + } + return err +} + // RunDispatcher runs the main loop of the dispatcher until receiving a message // on the dispatcher.DoneProcessing channel. It also installs a signal handler // to terminate gracefully on SIGINT, SIGTERM or SIGQUIT.