feat(cmd/daemon): new flag to set clean cache interval
This commit is contained in:
parent
13fcb9776d
commit
64590c1194
@ -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")
|
||||
|
||||
}
|
||||
|
@ -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 {
|
||||
|
Loading…
Reference in New Issue
Block a user