feat(cmd/daemon): new flag to set clean cache interval

This commit is contained in:
Markus Pesch 2019-06-16 23:15:26 +02:00
parent 13fcb9776d
commit 64590c1194
Signed by: volker.raschek
GPG Key ID: 852BCC170D81A982
2 changed files with 14 additions and 6 deletions

View File

@ -2,6 +2,7 @@ package daemon
import (
"log"
"time"
"github.com/go-flucky/flucky/pkg/config"
"github.com/go-flucky/flucky/pkg/daemon"
@ -10,6 +11,7 @@ import (
var compression bool
var configFile string
var cleanCacheIntervall string
var daemonCmd = &cobra.Command{
Use: "daemon",
@ -21,9 +23,14 @@ var daemonCmd = &cobra.Command{
log.Fatalln(err)
}
err = daemon.Start(cnf, compression)
duration, err := time.ParseDuration(cleanCacheIntervall)
if err != nil {
panic(err)
log.Fatalf("Can not parse clean cache interval into duration time: %v", err)
}
err = daemon.Start(cnf, duration, compression)
if err != nil {
log.Fatalln(err)
}
},
@ -32,6 +39,7 @@ var daemonCmd = &cobra.Command{
func InitCmd(cmd *cobra.Command, cnfFile string) {
configFile = cnfFile
cmd.AddCommand(daemonCmd)
daemonCmd.Flags().BoolVarP(&compression, "compression", "c", true, "Compress measured values")
daemonCmd.Flags().BoolVar(&compression, "compression", true, "Compress measured values")
daemonCmd.Flags().StringVar(&cleanCacheIntervall, "clean-cache-intervall", "30m", "Minute intervall to clean cache and write measured values into logfile")
}

View File

@ -16,7 +16,9 @@ import (
)
// Start the daemon
func Start(cnf *config.Configuration, compression bool) error {
func Start(cnf *config.Configuration, cleanCacheIntervall time.Duration, compression bool) error {
ticker := time.Tick(cleanCacheIntervall)
interrupt := make(chan os.Signal, 1)
signal.Notify(interrupt, os.Interrupt, os.Kill, syscall.SIGTERM)
@ -30,8 +32,6 @@ func Start(cnf *config.Configuration, compression bool) error {
temperatures := make([]*types.Temperature, 0)
ticker := time.Tick(time.Second * 300)
rgbLEDs := cnf.GetRGBLEDs(config.ENABLED)
err := rgbled.Green(rgbLEDs)
if err != nil {