Client handles periodic fingerprinters

This commit is contained in:
Alex Dadgar 2015-11-05 13:41:41 -08:00
parent 5f84878ffb
commit 5f1b6e70b0
2 changed files with 25 additions and 1 deletions

View file

@ -443,11 +443,35 @@ func (c *Client) fingerprint() error {
if applies { if applies {
applied = append(applied, name) applied = append(applied, name)
} }
p, period := f.Periodic()
if p {
// TODO: If more periodic fingerprinters are added, then
// fingerprintPeriodic should be used to handle all the periodic
// fingerprinters by using a priority queue.
go c.fingerprintPeriodic(name, f, period)
}
} }
c.logger.Printf("[DEBUG] client: applied fingerprints %v", applied) c.logger.Printf("[DEBUG] client: applied fingerprints %v", applied)
return nil return nil
} }
// fingerprintPeriodic runs a fingerprinter at the specified duration. If the
// fingerprinter returns an error, the function exits.
func (c *Client) fingerprintPeriodic(name string, f fingerprint.Fingerprint, d time.Duration) {
c.logger.Printf("[DEBUG] client: periodically fingerprinting %v at duration %v", name, d)
for {
select {
case <-time.After(d):
if _, err := f.Fingerprint(c.config, c.config.Node); err != nil {
c.logger.Printf("[DEBUG] client: disabling periodic fingerprinting for %v: %v", name, err)
return
}
case <-c.shutdownCh:
return
}
}
}
// setupDrivers is used to find the available drivers // setupDrivers is used to find the available drivers
func (c *Client) setupDrivers() error { func (c *Client) setupDrivers() error {
var avail []string var avail []string

View file

@ -65,5 +65,5 @@ func (f *ConsulFingerprint) Fingerprint(config *client.Config, node *structs.Nod
} }
func (f *ConsulFingerprint) Periodic() (bool, time.Duration) { func (f *ConsulFingerprint) Periodic() (bool, time.Duration) {
return false, 15 * time.Second return true, 15 * time.Second
} }