make no-telemetry request async

This commit is contained in:
sawka 2024-09-23 20:47:39 -07:00
parent 3ea8f45284
commit 91a85e06c8

View File

@ -110,6 +110,25 @@ func (cs *ClientService) AgreeTos(ctx context.Context) (waveobj.UpdatesRtnType,
return waveobj.ContextGetUpdatesRtn(ctx), nil return waveobj.ContextGetUpdatesRtn(ctx), nil
} }
func sendNoTelemetryUpdate(telemetryEnabled bool) {
ctx, cancelFn := context.WithTimeout(context.Background(), 5*time.Second)
defer cancelFn()
clientData, err := wstore.DBGetSingleton[*waveobj.Client](ctx)
if err != nil {
log.Printf("telemetry update: error getting client data: %v\n", err)
return
}
if clientData == nil {
log.Printf("telemetry update: client data is nil\n")
return
}
err = wcloud.SendNoTelemetryUpdate(ctx, clientData.OID, !telemetryEnabled)
if err != nil {
log.Printf("[error] sending no-telemetry update: %v\n", err)
return
}
}
func (cs *ClientService) TelemetryUpdate(ctx context.Context, telemetryEnabled bool) error { func (cs *ClientService) TelemetryUpdate(ctx context.Context, telemetryEnabled bool) error {
meta := waveobj.MetaMapType{ meta := waveobj.MetaMapType{
wconfig.ConfigKey_TelemetryEnabled: telemetryEnabled, wconfig.ConfigKey_TelemetryEnabled: telemetryEnabled,
@ -118,17 +137,6 @@ func (cs *ClientService) TelemetryUpdate(ctx context.Context, telemetryEnabled b
if err != nil { if err != nil {
return fmt.Errorf("error setting telemetry value: %w", err) return fmt.Errorf("error setting telemetry value: %w", err)
} }
clientData, err := wstore.DBGetSingleton[*waveobj.Client](ctx) go sendNoTelemetryUpdate(telemetryEnabled)
if err != nil {
return fmt.Errorf("error getting client data: %w", err)
}
if clientData == nil {
return fmt.Errorf("client data is nil")
}
telemetryErr := wcloud.SendNoTelemetryUpdate(ctx, clientData.OID, !telemetryEnabled)
if telemetryErr != nil {
// don't return error here, just log
log.Printf("[error] sending telemetry update: %v\n", telemetryErr)
}
return nil return nil
} }