-func (dispatcher *Dispatcher) handleUpdate(container Container) {
- if dispatcher.updateMine(container) {
- if container.State == Complete || container.State == Cancelled {
- log.Printf("Container %v now in state %v", container.UUID, container.State)
- dispatcher.notMine(container.UUID)
- }
+func (dispatcher *Dispatcher) handleUpdate(container arvados.Container) {
+ if container.State == Queued && dispatcher.checkMine(container, false) {
+ // If we previously started the job, something failed, and it
+ // was re-queued, this dispatcher might still be monitoring it.
+ // Stop the existing monitor, then try to lock and run it
+ // again.
+ dispatcher.notMine(container.UUID)
+ }
+
+ if container.LockedByUUID != dispatcher.Auth.UUID && container.State != Queued {
+ // If container is Complete, Cancelled, or Queued, LockedByUUID
+ // will be nil. If the container was formerly Locked, moved
+ // back to Queued and then locked by another dispatcher,
+ // LockedByUUID will be different. In either case, we want
+ // to stop monitoring it.
+ log.Printf("Container %v now in state %q with locked_by_uuid %q", container.UUID, container.State, container.LockedByUUID)
+ dispatcher.notMine(container.UUID)
+ return
+ }
+
+ if dispatcher.checkMine(container, true) {
+ // Already monitored, sent status update