mirror of
https://github.com/kemko/nomad.git
synced 2026-01-03 17:05:43 +03:00
Some of the context uses in TR hooks are useless (Killed during Stop never seems meaningful). None of the hooks are interruptable for graceful shutdown which is unfortunate and probably needs fixing.
33 lines
801 B
Go
33 lines
801 B
Go
package allocrunner
|
|
|
|
import (
|
|
"context"
|
|
|
|
log "github.com/hashicorp/go-hclog"
|
|
"github.com/hashicorp/nomad/client/allocwatcher"
|
|
)
|
|
|
|
// upstreamAllocsHook waits for a PrevAllocWatcher to exit before allowing
|
|
// an allocation to be executed
|
|
type upstreamAllocsHook struct {
|
|
allocWatcher allocwatcher.PrevAllocWatcher
|
|
logger log.Logger
|
|
}
|
|
|
|
func newUpstreamAllocsHook(logger log.Logger, allocWatcher allocwatcher.PrevAllocWatcher) *upstreamAllocsHook {
|
|
h := &upstreamAllocsHook{
|
|
allocWatcher: allocWatcher,
|
|
}
|
|
h.logger = logger.Named(h.Name())
|
|
return h
|
|
}
|
|
|
|
func (h *upstreamAllocsHook) Name() string {
|
|
return "await_previous_allocations"
|
|
}
|
|
|
|
func (h *upstreamAllocsHook) Prerun() error {
|
|
// Wait for a previous alloc - if any - to terminate
|
|
return h.allocWatcher.Wait(context.Background())
|
|
}
|