Renamed NomadChecks to CheckRunner and a fix for checkrunner start

This commit is contained in:
Diptanu Choudhury 2016-03-25 10:36:31 -07:00
parent 966b4ca26f
commit 4b1f7fa274
2 changed files with 17 additions and 15 deletions

View file

@ -25,26 +25,26 @@ type CheckRunner struct {
// NewCheckRunner configures and returns a CheckRunner
func NewCheckRunner(check Check, runCheck func(Check), logger *log.Logger) *CheckRunner {
nc := NomadCheck{
cr := CheckRunner{
check: check,
runCheck: runCheck,
logger: logger,
stopCh: make(chan struct{}),
}
return &nc
return &cr
}
// Start is used to start the check. The check runs until stop is called
func (r *CheckRunner) Start() {
r.startedLock.Lock()
defer r.startedLock.Unlock()
if r.started {
return
}
r.started = true
r.stopLock.Lock()
defer r.stopLock.Unlock()
r.stopCh = make(chan struct{})
go r.run()
r.started = true
}
// Stop is used to stop the check.

View file

@ -100,7 +100,7 @@ func NewConsulService(config *ConsulConfig, logger *log.Logger, allocID string)
logger: logger,
trackedServices: make(map[string]*consul.AgentService),
trackedChecks: make(map[string]*consul.AgentCheckRegistration),
nomadChecks: make(map[string]*NomadCheck),
checkRunners: make(map[string]*CheckRunner),
shutdownCh: make(chan struct{}),
}
@ -139,11 +139,23 @@ func (c *ConsulService) SyncTask(task *structs.Task) error {
taskServices[srv.ID] = srv
for _, chk := range service.Checks {
// Create a consul check registration
chkReg, err := c.createCheckReg(chk, srv)
if err != nil {
mErr.Errors = append(mErr.Errors, err)
continue
}
// creating a nomad check if we have to handle this particular check type
if _, ok := c.delegateChecks[chk.Type]; ok {
nc, err := c.createCheck(chk, chkReg.ID)
if err != nil {
mErr.Errors = append(mErr.Errors, err)
continue
}
cr := NewCheckRunner(nc, c.runCheck, c.logger)
c.checkRunners[nc.ID()] = cr
}
if _, ok := c.trackedChecks[chkReg.ID]; !ok {
if err := c.registerCheck(chkReg); err != nil {
mErr.Errors = append(mErr.Errors, err)
@ -260,16 +272,6 @@ func (c *ConsulService) createCheckReg(check *structs.ServiceCheck, service *con
default:
return nil, fmt.Errorf("check type %q not valid", check.Type)
}
// creating a nomad check if we have to handle this particular check type
if _, ok := c.delegateChecks[check.Type]; ok {
chk, err := c.createCheck(check, chkReg.ID)
if err != nil {
return nil, err
}
cr := NewCheckRunner(chk, c.runCheck, c.logger)
c.checkRunners[chk.ID()] = cr
}
return &chkReg, nil
}