fix(pkg/sensor): use context to terminate go routines

This commit is contained in:
2019-06-17 23:37:48 +02:00
parent 502e3b3b1c
commit 2941f7a527
11 changed files with 298 additions and 80 deletions

View File

@ -11,7 +11,8 @@ import (
var compression bool
var configFile string
var cleanCacheIntervall string
var cleanCacheInterval string
var round float64
var daemonCmd = &cobra.Command{
Use: "daemon",
@ -23,12 +24,12 @@ var daemonCmd = &cobra.Command{
log.Fatalln(err)
}
duration, err := time.ParseDuration(cleanCacheIntervall)
duration, err := time.ParseDuration(cleanCacheInterval)
if err != nil {
log.Fatalf("Can not parse clean cache interval into duration time: %v", err)
}
err = daemon.Start(cnf, duration, compression)
err = daemon.Start(cnf, duration, compression, round)
if err != nil {
log.Fatalln(err)
}
@ -40,6 +41,6 @@ func InitCmd(cmd *cobra.Command, cnfFile string) {
configFile = cnfFile
cmd.AddCommand(daemonCmd)
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")
daemonCmd.Flags().StringVar(&cleanCacheInterval, "clean-cache-interval", "5m", "Minute intervall to clean cache and write measured values into logfile")
daemonCmd.Flags().Float64Var(&round, "round", 0.25, "Round values. The value 0 deactivates the function")
}

View File

@ -14,6 +14,7 @@ import (
var compression bool
var logs bool
var round float64
var readTemperatureCmd = &cobra.Command{
Use: "read",
@ -35,8 +36,7 @@ var readTemperatureCmd = &cobra.Command{
temperatureSensors = cnf.GetTemperatureSensorsByName(args)
}
// read temperature from sensors
temperatures, err := sensor.ReadTemperatures(temperatureSensors)
temperatures, err := sensor.ReadTemperatures(temperatureSensors, round)
if err != nil {
log.Fatalln(err)
}
@ -55,6 +55,7 @@ var readTemperatureCmd = &cobra.Command{
func init() {
temperatureCmd.AddCommand(readTemperatureCmd)
readTemperatureCmd.Flags().BoolVarP(&logs, "logs", "l", true, "Log temperature")
readTemperatureCmd.Flags().BoolVarP(&compression, "compression", "c", true, "Compress measured with logged temperatures")
readTemperatureCmd.Flags().BoolVar(&logs, "logs", true, "Log temperature")
readTemperatureCmd.Flags().BoolVar(&compression, "compression", true, "Compress measured with logged temperatures")
readTemperatureCmd.Flags().Float64VarP(&round, "round", "r", 0.25, "Round values. The value 0 deactivates the function")
}