diff --git a/nomad/plan_queue.go b/nomad/plan_queue.go index 69fee9549..cb2e5eab5 100644 --- a/nomad/plan_queue.go +++ b/nomad/plan_queue.go @@ -73,6 +73,13 @@ func (p *pendingPlan) respond(result *structs.PlanResult, err error) { // priority queue type PendingPlans []*pendingPlan +// Enabled is used to check if the queue is enabled. +func (q *PlanQueue) Enabled() bool { + q.l.RLock() + defer q.l.RUnlock() + return q.enabled +} + // SetEnabled is used to control if the queue is enabled. The queue // should only be enabled on the active leader. func (q *PlanQueue) SetEnabled(enabled bool) { diff --git a/nomad/plan_queue_test.go b/nomad/plan_queue_test.go index 0e4a26a82..fe1e30b3b 100644 --- a/nomad/plan_queue_test.go +++ b/nomad/plan_queue_test.go @@ -27,7 +27,13 @@ func mockPlanResult() *structs.PlanResult { func TestPlanQueue_Enqueue_Dequeue(t *testing.T) { pq := testPlanQueue(t) + if pq.Enabled() { + t.Fatalf("should not be enabled") + } pq.SetEnabled(true) + if !pq.Enabled() { + t.Fatalf("should be enabled") + } plan := mockPlan() future, err := pq.Enqueue(plan)