github.com/iqoqo/nomad@v0.11.3-0.20200911112621-d7021c74d101/client/allocrunner/upstream_allocs_hook.go (about) 1 package allocrunner 2 3 import ( 4 "context" 5 6 log "github.com/hashicorp/go-hclog" 7 "github.com/hashicorp/nomad/client/allocwatcher" 8 ) 9 10 // upstreamAllocsHook waits for a PrevAllocWatcher to exit before allowing 11 // an allocation to be executed 12 type upstreamAllocsHook struct { 13 allocWatcher allocwatcher.PrevAllocWatcher 14 logger log.Logger 15 } 16 17 func newUpstreamAllocsHook(logger log.Logger, allocWatcher allocwatcher.PrevAllocWatcher) *upstreamAllocsHook { 18 h := &upstreamAllocsHook{ 19 allocWatcher: allocWatcher, 20 } 21 h.logger = logger.Named(h.Name()) 22 return h 23 } 24 25 func (h *upstreamAllocsHook) Name() string { 26 return "await_previous_allocations" 27 } 28 29 func (h *upstreamAllocsHook) Prerun() error { 30 // Wait for a previous alloc - if any - to terminate 31 return h.allocWatcher.Wait(context.Background()) 32 }