startHealthProbing

fun startHealthProbing(scope: CoroutineScope, interval: Duration = 30.seconds): Job(source)

Starts actively probing every currently-open provider on a fixed interval, instead of waiting for real traffic to pass through execute and incidentally test them.

Without this, a lower-priority provider that recovers while a higher-priority one keeps satisfying every call may never get re-tried at all (since execute always returns as soon as any provider succeeds) -- and even the top provider only gets re-tested exactly as often as real traffic happens to arrive, which can be a long wait on a quiet system. Active probing decouples recovery detection from real traffic entirely: by the time a real request arrives, an open provider that has actually recovered is already back in rotation (or at least progressing through its circuit breaker's half-open state).

A probe that succeeds or fails updates that provider's statistics exactly like a real execute call would; a provider whose circuit isn't open yet (still within its own resetTimeout) is left alone -- probing never bypasses the breaker's own timing.

val transport = failover<Connection> {
provider("websocket") { connectWebSocket() }
provider("mqtt") { connectMqtt() }
}
val probing = transport.startHealthProbing(applicationScope, interval = 30.seconds)
// ... later, on shutdown:
probing.cancel()

Return

The Job running the probing loop.

Parameters

scope

Coroutine scope the background probing loop is launched in -- cancel the returned Job (or cancel scope itself) to stop probing.

interval

How often to probe every currently-open provider.