2018-12-05 18:18:04 +00:00
|
|
|
package allocrunner
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
|
|
|
|
log "github.com/hashicorp/go-hclog"
|
|
|
|
"github.com/hashicorp/nomad/client/allocwatcher"
|
|
|
|
)
|
|
|
|
|
2018-12-06 11:15:59 +00:00
|
|
|
// upstreamAllocsHook waits for a PrevAllocWatcher to exit before allowing
|
2018-12-05 18:18:04 +00:00
|
|
|
// an allocation to be executed
|
2018-12-06 11:15:59 +00:00
|
|
|
type upstreamAllocsHook struct {
|
2018-12-05 18:18:04 +00:00
|
|
|
allocWatcher allocwatcher.PrevAllocWatcher
|
|
|
|
logger log.Logger
|
|
|
|
}
|
|
|
|
|
2018-12-06 11:15:59 +00:00
|
|
|
func newUpstreamAllocsHook(logger log.Logger, allocWatcher allocwatcher.PrevAllocWatcher) *upstreamAllocsHook {
|
|
|
|
h := &upstreamAllocsHook{
|
2018-12-05 18:18:04 +00:00
|
|
|
allocWatcher: allocWatcher,
|
|
|
|
}
|
|
|
|
h.logger = logger.Named(h.Name())
|
|
|
|
return h
|
|
|
|
}
|
|
|
|
|
2018-12-06 11:15:59 +00:00
|
|
|
func (h *upstreamAllocsHook) Name() string {
|
|
|
|
return "await_previous_allocations"
|
2018-12-05 18:18:04 +00:00
|
|
|
}
|
|
|
|
|
2019-03-12 22:03:54 +00:00
|
|
|
func (h *upstreamAllocsHook) Prerun() error {
|
2018-12-05 18:18:04 +00:00
|
|
|
// Wait for a previous alloc - if any - to terminate
|
2019-03-12 22:03:54 +00:00
|
|
|
return h.allocWatcher.Wait(context.Background())
|
2018-12-05 18:18:04 +00:00
|
|
|
}
|