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.
This commit is contained in:
Markus Pesch 2020-10-07 23:59:27 +02:00
parent 0fc4aa7c28
commit 1701db7b8e
Signed by: volker.raschek
GPG Key ID: 852BCC170D81A982
2 changed files with 10 additions and 7 deletions

View File

@ -18,9 +18,7 @@ func InitCmd(cmd *cobra.Command) error {
RunE: run, RunE: run,
} }
daemonCmd.Flags().Bool("compression", true, "Compress measured values") daemonCmd.Flags().Uint("cached-values", 500, "Number of measured values in the cache before they are stored in the database")
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")
cmd.AddCommand(daemonCmd) cmd.AddCommand(daemonCmd)
return nil return nil
@ -32,6 +30,11 @@ func run(cmd *cobra.Command, args []string) error {
return fmt.Errorf("No config file defined: %v", err) 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") // logLevel, err := cmd.Flags().GetString("loglevel")
// if err != nil { // if err != nil {
// return fmt.Errorf("No loglevel defined: %v", err) // return fmt.Errorf("No loglevel defined: %v", err)
@ -44,5 +47,5 @@ func run(cmd *cobra.Command, args []string) error {
return err return err
} }
return daemon.Start(cnf, flogger) return daemon.Start(cnf, cachedEntries, flogger)
} }

View File

@ -14,7 +14,7 @@ import (
"git.cryptic.systems/volker.raschek/go-logger" "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) // load data source name (dsn)
dsnURL, err := url.Parse(cnf.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 { for {
select { select {
case measuredValue := <-measuredValueChannel: case measuredValue := <-measuredValueChannel:
@ -114,7 +114,7 @@ func Start(cnf *config.Config, flogger logger.Logger) error {
if err != nil { if err != nil {
flogger.Error("%v", err) flogger.Error("%v", err)
} }
measuredValues = make([]*types.MeasuredValue, 0, 10) measuredValues = make([]*types.MeasuredValue, 0, cachedEntries)
} }
case signal := <-interruptChannel: case signal := <-interruptChannel: