Skip to content

Commit

Permalink
Client handles periodic fingerprinters
Browse files Browse the repository at this point in the history
  • Loading branch information
dadgar committed Nov 5, 2015
1 parent 8e0ab77 commit f43c067
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
24 changes: 24 additions & 0 deletions client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -443,11 +443,35 @@ func (c *Client) fingerprint() error {
if applies {
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)
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
func (c *Client) setupDrivers() error {
var avail []string
Expand Down
2 changes: 1 addition & 1 deletion client/fingerprint/consul.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,5 +65,5 @@ func (f *ConsulFingerprint) Fingerprint(config *client.Config, node *structs.Nod
}

func (f *ConsulFingerprint) Periodic() (bool, time.Duration) {
return false, 15 * time.Second
return true, 15 * time.Second
}

0 comments on commit f43c067

Please sign in to comment.