Provider loop discovery almost finished

Provider lookup will lookup on startup, do the healthcheck until the
stream starts and also restart on stream closure or provider stall
This commit is contained in:
2026-09-12 23:28:15 +01:00
parent 196e1d8916
commit 528c62288a
8 changed files with 114 additions and 19 deletions
+7
View File
@@ -79,6 +79,13 @@ func NewBeamNGProvider(ip string, port int) (*BeamNG, error) {
return provider, nil
}
func (b *BeamNG) Close() {
}
func (b *BeamNG) IsAlive(timeout time.Duration) bool {
return true
}
func (b *BeamNG) StopStream() {
if b.streamCancel == nil {
return
-6
View File
@@ -31,9 +31,3 @@ func IsRunning() bool {
// Think of a better number or something
return n >= 80
}
// Stalled
// TODO: needs to be implemented
func (i *BeamNG) Stalled() bool {
return false
}
+18
View File
@@ -108,6 +108,13 @@ func NewIRacingProvider(
return provider, nil
}
func (i *IRacing) Close() {
// Need to find a way of gracefully closing the channel
// close(i.streamCh)
i.SDK.Close()
i.ticker.Stop()
}
func (i *IRacing) isDataAvailable() bool {
// Its offline telemetry, data must be available
if i.SDK.File == nil {
@@ -126,6 +133,8 @@ func (i *IRacing) stream(ctx context.Context) {
i.data.InitialTime = time.Now()
go func() {
defer close(i.streamCh)
// Put this into the configuration file
consecutiveTimeouts := 0
maxTimeouts := 30
@@ -140,6 +149,7 @@ func (i *IRacing) stream(ctx context.Context) {
if i.SDK.CheckForDataEvent(time.Duration(dataEvTimeout) * time.Millisecond) {
consecutiveTimeouts = 0
i.logger.Debug("sending data", "timeouts", consecutiveTimeouts)
i.readData()
// Publish data
@@ -253,3 +263,11 @@ func (i *IRacing) Subscribe(requestFields map[int16]telemetry.FieldID) {
i.logger.Debug(fmt.Sprintf("Subscribed: %+v\n", i.data.ActiveBinds))
}
func (i *IRacing) IsAlive(timeout time.Duration) bool {
if !i.SDK.CheckForDataEvent(timeout) {
return false
}
return true
}
-4
View File
@@ -31,7 +31,3 @@ func IsRunning() bool {
return true
}
func (i *IRacing) Stalled() bool {
return i.Stalled()
}