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