refac(cmd): mergeing, ordering and outsourcing cmd subcommands

This commit is contained in:
2020-01-13 22:26:41 +01:00
parent 0261203395
commit 0765bd29d1
34 changed files with 1209 additions and 1302 deletions

View File

@ -15,19 +15,9 @@ import (
)
var (
postgresHost = "markus-pc.trier.cryptic.systems"
postgresPort = "5432"
postgresDatabase = "postgres"
postgresUser = "postgres"
postgresPassword = "postgres"
flogger = logger.NewSilentLogger()
flogger = logger.NewDefaultLogger(logger.LogLevelDebug)
)
func SetLogger(logger logger.Logger) {
flogger = logger
}
// Start the daemon
func Start(cnf *config.Configuration, cacheSize uint, compression bool, round float64) error {
@ -59,8 +49,8 @@ func Start(cnf *config.Configuration, cacheSize uint, compression bool, round fl
measuredValueChannel := make(chan *types.MeasuredValue, 0)
// Info
flogger.Info("Use compression: %v", compression)
flogger.Info("Round: %v", round)
flogger.Debug("Use compression: %v", compression)
flogger.Debug("Round values to: %v", round)
// Init semaphoreChannel
semaphoreChannels := make(map[string]chan struct{})
@ -77,7 +67,6 @@ func Start(cnf *config.Configuration, cacheSize uint, compression bool, round fl
for {
select {
case <-ctx.Done():
errorChannel <- fmt.Errorf("Closed context: %v", ctx.Err().Error())
return
case <-semaphoreChannels[sensor.GetID()]:
measuredValues, err := sensor.Read()
@ -97,7 +86,6 @@ func Start(cnf *config.Configuration, cacheSize uint, compression bool, round fl
for {
select {
case <-ctx.Done():
errorChannel <- fmt.Errorf("Closed context: %v", ctx.Err().Error())
return
case <-sensor.GetTicker().C:
semaphoreChannels[sensor.GetID()] <- struct{}{}
@ -114,7 +102,7 @@ func Start(cnf *config.Configuration, cacheSize uint, compression bool, round fl
return
case measuredValue := <-measuredValueChannel:
cache.Add(measuredValue)
debugChannel <- fmt.Sprintf("CacheStore ID %v: %v - %v - %v", cache.Size(), measuredValue.SensorID, measuredValue.ValueType, measuredValue.Value)
debugChannel <- fmt.Sprintf("CacheStore ID: %v, Sensor ID: %v, Type: %v, Value: %v", cache.Size(), measuredValue.SensorID, measuredValue.ValueType, measuredValue.Value)
if cache.Size() >= int(cacheSize) {
debugChannel <- fmt.Sprint("Write cache into storage endpoint")
err := cache.WriteToEndpoint()