Skip to content
This repository has been archived by the owner on Nov 30, 2021. It is now read-only.

Commit

Permalink
Merge pull request #3854 from mboersma/fix-logger-refresh
Browse files Browse the repository at this point in the history
fix(logger): adjust publish and ttl times to seconds
  • Loading branch information
mboersma committed Jun 11, 2015
2 parents 909df2d + 517cb1b commit c73c8f7
Showing 1 changed file with 13 additions and 6 deletions.
19 changes: 13 additions & 6 deletions logger/main.go
Expand Up @@ -59,7 +59,7 @@ func main() {

go syslogd.Listen(exitChan, cleanupChan, drainChan, fmt.Sprintf("%s:%d", logAddr, logPort))
if enablePublish {
go publishService(exitChan, client, publishHost, publishPath, strconv.Itoa(logPort), uint64(time.Duration(publishTTL).Seconds()))
go publishService(exitChan, client, publishHost, publishPath, strconv.Itoa(logPort), uint64(time.Duration(publishTTL)*time.Second))
}

// HACK (bacongobbler): poll etcd for changes in the log drain value
Expand All @@ -76,7 +76,7 @@ func main() {
if resp != nil && resp.Node != nil {
drainChan <- resp.Node.Value
}
time.Sleep(time.Duration(publishInterval))
time.Sleep(time.Duration(publishInterval) * time.Second)
}
}()

Expand All @@ -91,14 +91,21 @@ func main() {
}
}

func publishService(exitChan chan bool, client *etcd.Client, host string, etcdPath string, port string, ttl uint64) {
t := time.NewTicker(time.Duration(publishInterval))
// publishKeys sets relevant etcd keys with a time-to-live.
func publishKeys(client *etcd.Client, host, etcdPath, port string, ttl uint64) {
setEtcd(client, etcdPath+"/host", host, ttl)
setEtcd(client, etcdPath+"/port", port, ttl)
}

// publishServices publishes keys immediately, then every publishInterval seconds until it receives
// something on exitChan.
func publishService(exitChan chan bool, client *etcd.Client, host string, etcdPath string, port string, ttl uint64) {
publishKeys(client, host, etcdPath, port, ttl)
t := time.NewTicker(time.Duration(publishInterval) * time.Second)
for {
select {
case <-t.C:
setEtcd(client, etcdPath+"/host", host, ttl)
setEtcd(client, etcdPath+"/port", port, ttl)
publishKeys(client, host, etcdPath, port, ttl)
case <-exitChan:
return
}
Expand Down

0 comments on commit c73c8f7

Please sign in to comment.