diff --git a/cmd/daemon/daemon.go b/cmd/daemon/daemon.go index 57f516f..d77e0bc 100644 --- a/cmd/daemon/daemon.go +++ b/cmd/daemon/daemon.go @@ -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") } diff --git a/pkg/daemon/daemon.go b/pkg/daemon/daemon.go index f0b7490..3ea61e9 100644 --- a/pkg/daemon/daemon.go +++ b/pkg/daemon/daemon.go @@ -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 {