Increment waitgroup before goroutine
This commit is contained in:
parent
8325f2f3c6
commit
bc6f62af23
1 changed files with 9 additions and 11 deletions
|
@ -49,8 +49,7 @@ func bool2ChamberState(state bool) dal.ChamberState {
|
||||||
return dal.ChamberStateIdle
|
return dal.ChamberStateIdle
|
||||||
}
|
}
|
||||||
|
|
||||||
func mainLoop(db *dal.DAL) {
|
func mainLoop(db *dal.DAL, wg *sync.WaitGroup) {
|
||||||
wg.Add(1)
|
|
||||||
defer wg.Done()
|
defer wg.Done()
|
||||||
|
|
||||||
for {
|
for {
|
||||||
|
@ -89,13 +88,13 @@ func mainLoop(db *dal.DAL) {
|
||||||
|
|
||||||
switch reading.Sensor {
|
switch reading.Sensor {
|
||||||
case config.Temperature.AmbientSensor:
|
case config.Temperature.AmbientSensor:
|
||||||
hysteresis.UpdateAmbientTemperature(reading.Value)
|
hysteresis.UpdateAmbientTemperature(reading.Degrees())
|
||||||
|
|
||||||
case config.Temperature.ChamberSensor:
|
case config.Temperature.ChamberSensor:
|
||||||
hysteresis.UpdateChamberTemperature(reading.Value)
|
hysteresis.UpdateChamberTemperature(reading.Degrees())
|
||||||
|
|
||||||
case config.Temperature.WortSensor:
|
case config.Temperature.WortSensor:
|
||||||
hysteresis.UpdateWortTemperature(reading.Value)
|
hysteresis.UpdateWortTemperature(reading.Degrees())
|
||||||
}
|
}
|
||||||
|
|
||||||
dbCtx, cancel := context.WithTimeout(ctx, 10*time.Second)
|
dbCtx, cancel := context.WithTimeout(ctx, 10*time.Second)
|
||||||
|
@ -103,7 +102,7 @@ func mainLoop(db *dal.DAL) {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Error().Err(err).Msg("Failed to start DB transaction")
|
log.Error().Err(err).Msg("Failed to start DB transaction")
|
||||||
} else {
|
} else {
|
||||||
dal.SaveTemperatureReading(dbCtx, tx, reading.Sensor, reading.Value)
|
dal.SaveTemperatureReading(dbCtx, tx, reading.Sensor, reading.MilliDegrees)
|
||||||
err = tx.Commit()
|
err = tx.Commit()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Error().Err(err).Msg("Failed to commit DB transaction")
|
log.Error().Err(err).Msg("Failed to commit DB transaction")
|
||||||
|
@ -118,7 +117,7 @@ func main() {
|
||||||
// Sentry
|
// Sentry
|
||||||
err := sentry.Init(sentry.ClientOptions{
|
err := sentry.Init(sentry.ClientOptions{
|
||||||
Dsn: "https://7278625538334140991ce433e0ad292f@sentry.joco.dk/24",
|
Dsn: "https://7278625538334140991ce433e0ad292f@sentry.joco.dk/24",
|
||||||
//TracesSampleRate: 0.1,
|
TracesSampleRate: 0.01,
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal().Err(err).Msg("Failed to initialize Sentry.")
|
log.Fatal().Err(err).Msg("Failed to initialize Sentry.")
|
||||||
|
@ -158,8 +157,6 @@ func main() {
|
||||||
reloadConfig()
|
reloadConfig()
|
||||||
|
|
||||||
// Database
|
// Database
|
||||||
log.Info().Str("dsn", config.Db.Dsn).Msg("Initializing DB")
|
|
||||||
|
|
||||||
migrator, err := dal.NewMigrator(config.Db.Dsn)
|
migrator, err := dal.NewMigrator(config.Db.Dsn)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal().Err(err).Msg("Error initializing DB migrations")
|
log.Fatal().Err(err).Msg("Error initializing DB migrations")
|
||||||
|
@ -205,8 +202,9 @@ func main() {
|
||||||
mux.HandleFunc("/state-changes", api.GetStateChanges)
|
mux.HandleFunc("/state-changes", api.GetStateChanges)
|
||||||
|
|
||||||
// Main
|
// Main
|
||||||
|
wg.Add(2)
|
||||||
go temperature.Serve(ctx, wg)
|
go temperature.Serve(ctx, wg)
|
||||||
go mainLoop(db)
|
go mainLoop(db, wg)
|
||||||
go srv.ListenAndServe()
|
go srv.ListenAndServe()
|
||||||
|
|
||||||
done := make(chan os.Signal, 1)
|
done := make(chan os.Signal, 1)
|
||||||
|
|
Loading…
Reference in a new issue