github.com/uchennaokeke444/nomad@v0.11.8/nomad/plan_endpoint.go (about) 1 package nomad 2 3 import ( 4 "time" 5 6 metrics "github.com/armon/go-metrics" 7 log "github.com/hashicorp/go-hclog" 8 9 "github.com/hashicorp/nomad/nomad/structs" 10 ) 11 12 // Plan endpoint is used for plan interactions 13 type Plan struct { 14 srv *Server 15 logger log.Logger 16 } 17 18 // Submit is used to submit a plan to the leader 19 func (p *Plan) Submit(args *structs.PlanRequest, reply *structs.PlanResponse) error { 20 if done, err := p.srv.forward("Plan.Submit", args, args, reply); done { 21 return err 22 } 23 defer metrics.MeasureSince([]string{"nomad", "plan", "submit"}, time.Now()) 24 25 // Pause the Nack timer for the eval as it is making progress as long as it 26 // is in the plan queue. We resume immediately after we get a result to 27 // handle the case that the receiving worker dies. 28 plan := args.Plan 29 id := plan.EvalID 30 token := plan.EvalToken 31 if err := p.srv.evalBroker.PauseNackTimeout(id, token); err != nil { 32 return err 33 } 34 defer p.srv.evalBroker.ResumeNackTimeout(id, token) 35 36 // Submit the plan to the queue 37 future, err := p.srv.planQueue.Enqueue(plan) 38 if err != nil { 39 return err 40 } 41 42 // Wait for the results 43 result, err := future.Wait() 44 if err != nil { 45 return err 46 } 47 48 // Package the result 49 reply.Result = result 50 reply.Index = result.AllocIndex 51 return nil 52 }