From 1701db7b8e69233bd763da382a376e14734115dd Mon Sep 17 00:00:00 2001 From: Markus Pesch Date: Wed, 7 Oct 2020 23:59:27 +0200 Subject: [PATCH] fix: define cache values The number of measured values in the cache before they are stored in the database can not be defined over the flag --cached-values. --- cli/daemon/daemon.go | 11 +++++++---- pkg/daemon/daemon.go | 6 +++--- 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/cli/daemon/daemon.go b/cli/daemon/daemon.go index e5880d6..3d18593 100644 --- a/cli/daemon/daemon.go +++ b/cli/daemon/daemon.go @@ -18,9 +18,7 @@ func InitCmd(cmd *cobra.Command) error { RunE: run, } - daemonCmd.Flags().Bool("compression", true, "Compress measured values") - daemonCmd.Flags().Uint("cached-values", 500, "Number of cached values before saveing into the backend") - daemonCmd.Flags().Float64("round", 0.5, "Round values. The value 0 deactivates the function") + daemonCmd.Flags().Uint("cached-values", 500, "Number of measured values in the cache before they are stored in the database") cmd.AddCommand(daemonCmd) return nil @@ -32,6 +30,11 @@ func run(cmd *cobra.Command, args []string) error { return fmt.Errorf("No config file defined: %v", err) } + cachedEntries, err := cmd.Flags().GetUint("cached-values") + if err != nil { + return fmt.Errorf("No cached-entries defined") + } + // logLevel, err := cmd.Flags().GetString("loglevel") // if err != nil { // return fmt.Errorf("No loglevel defined: %v", err) @@ -44,5 +47,5 @@ func run(cmd *cobra.Command, args []string) error { return err } - return daemon.Start(cnf, flogger) + return daemon.Start(cnf, cachedEntries, flogger) } diff --git a/pkg/daemon/daemon.go b/pkg/daemon/daemon.go index f618b8f..4d0ffbf 100644 --- a/pkg/daemon/daemon.go +++ b/pkg/daemon/daemon.go @@ -14,7 +14,7 @@ import ( "git.cryptic.systems/volker.raschek/go-logger" ) -func Start(cnf *config.Config, flogger logger.Logger) error { +func Start(cnf *config.Config, cachedEntries uint, flogger logger.Logger) error { // load data source name (dsn) dsnURL, err := url.Parse(cnf.DSN) @@ -101,7 +101,7 @@ func Start(cnf *config.Config, flogger logger.Logger) error { } }() - measuredValues := make([]*types.MeasuredValue, 0, 10) + measuredValues := make([]*types.MeasuredValue, 0, cachedEntries) for { select { case measuredValue := <-measuredValueChannel: @@ -114,7 +114,7 @@ func Start(cnf *config.Config, flogger logger.Logger) error { if err != nil { flogger.Error("%v", err) } - measuredValues = make([]*types.MeasuredValue, 0, 10) + measuredValues = make([]*types.MeasuredValue, 0, cachedEntries) } case signal := <-interruptChannel: