Skip to content

Commit

Permalink
- more retry time to get configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
zakharenkodmytro committed Aug 12, 2024
1 parent 393ea7f commit 18affd3
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 24 deletions.
3 changes: 2 additions & 1 deletion config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,8 @@ func ReadConfig(logger zerolog.Logger, configFiles embed.FS, configURL, configFi

// Get secrets from remote config
remoteConfigPathOnDisk := "/opt/autopi/remote-config.json"
remoteConfig, err := util.Retry[Config](3, 1*time.Second, logger, func() (interface{}, error) {
// Retry for about 1 hour
remoteConfig, err := util.Retry[Config](11, 1*time.Second, logger, func() (interface{}, error) {
return GetRemoteConfig(configURL, remoteConfigPathOnDisk)
})

Expand Down
47 changes: 24 additions & 23 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,31 @@ func main() {
configURL = "https://device-config-dev.dimo.xyz"
}

lss := loggers.NewTemplateStore()
vinLogger := loggers.NewVINLogger(logger)

logger.Info().Msgf("Bluetooth name: %s", name)
logger.Info().Msgf("Version: %s", Version)
logger.Info().Msgf("Environment: %s", env)

coldBoot, err := isColdBoot(logger, unitID)
if err != nil {
logger.Fatal().Err(err).Msgf("Failed to get power management status: %s", err)
}
// if hw revision is anything other than 5.2, setup BLE
if hwRevision != bleUnsupportedHW {
err = setupBluez(name)
if err != nil {
logger.Fatal().Err(err).Msgf("Failed to setup BlueZ: %s", err)
}
app, cancel, obCancel := setupBluetoothApplication(logger, coldBoot, vinLogger, lss)
defer app.Close()
defer cancel()
defer obCancel()
}

// read config file
// will retry for about 1 hour in case if no internet connection, so we are not interrupt device pairing process
config, confErr := dimoConfig.ReadConfig(logger, configFiles, configURL, confFileName)
logger.Debug().Msgf("Config: %+v\n", config)
if confErr != nil {
Expand Down Expand Up @@ -146,29 +170,6 @@ func main() {
logger.Error().Ctx(context.WithValue(context.Background(), hooks.LogToMqtt, "true")).Msgf("Error from SignWeb3Certificate : %s", certErr.Error())
}

coldBoot, err := isColdBoot(logger, unitID)
if err != nil {
logger.Fatal().Err(err).Msgf("Failed to get power management status: %s", err)
}

logger.Info().Msgf("Bluetooth name: %s", name)
logger.Info().Msgf("Version: %s", Version)
logger.Info().Msgf("Environment: %s", env)

lss := loggers.NewTemplateStore()
vinLogger := loggers.NewVINLogger(logger)
// if hw revision is anything other than 5.2, setup BLE
if hwRevision != bleUnsupportedHW {
err = setupBluez(name)
if err != nil {
logger.Fatal().Err(err).Msgf("Failed to setup BlueZ: %s", err)
}
app, cancel, obCancel := setupBluetoothApplication(logger, coldBoot, vinLogger, lss)
defer app.Close()
defer cancel()
defer obCancel()
}

// block here until satisfy condition. future - way to know if device is being used as decoding device, eg. mapped to a specific template
// and we want to loosen some assumptions, eg. doesn't matter if not paired.
vehicleInfo, err := blockingGetVehicleInfo(logger, ethAddr, lss, *config)
Expand Down

0 comments on commit 18affd3

Please sign in to comment.