Skip to content

Commit d715a75

Browse files
func: add control context to run agent to prepare for ha mode (#651)
1 parent d05ab8f commit d715a75

File tree

2 files changed

+6
-3
lines changed

2 files changed

+6
-3
lines changed

agent/agent.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,11 +49,11 @@ func NewAgent(c *config.Agent, configPaths []string, logger hclog.Logger) *Agent
4949
}
5050
}
5151

52-
func (a *Agent) Run() error {
52+
func (a *Agent) Run(ctx context.Context) error {
5353
defer a.stop()
5454

5555
// Create context to handle propagation to downstream routines.
56-
ctx, cancel := context.WithCancel(context.Background())
56+
ctx, cancel := context.WithCancel(ctx)
5757
defer cancel()
5858

5959
// Generate the Nomad client.

command/agent.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
package command
55

66
import (
7+
"context"
78
"flag"
89
"fmt"
910
"sort"
@@ -335,7 +336,9 @@ func (c *AgentCommand) Run(args []string) int {
335336
go c.httpServer.Start()
336337
defer c.httpServer.Stop()
337338

338-
if err := c.agent.Run(); err != nil {
339+
ctx := context.Background()
340+
341+
if err := c.agent.Run(ctx); err != nil {
339342
logger.Error("failed to start agent", "error", err)
340343
return 1
341344
}

0 commit comments

Comments
 (0)