feat(desktop, device-initialization): Tools-Menü mit Backup-Option und Reset-Funktion ergänzt
Signed-off-by: Stefan Mogeritsch <stefan.mo.co@gmail.com>
This commit is contained in:
+38
-6
@@ -13,6 +13,11 @@ import kotlin.time.Duration.Companion.milliseconds
|
||||
|
||||
/**
|
||||
* Überwacht die Konnektivität zum API-Gateway.
|
||||
*
|
||||
* Robustere Strategie:
|
||||
* 1) /actuator/health/readiness
|
||||
* 2) /actuator/health (Fallback)
|
||||
* 3) /api/ping/simple (Fallback)
|
||||
*/
|
||||
class ConnectivityTracker : KoinComponent {
|
||||
private val client: HttpClient by inject(named("baseHttpClient"))
|
||||
@@ -24,20 +29,47 @@ class ConnectivityTracker : KoinComponent {
|
||||
fun startTracking() {
|
||||
if (scope.isActive && _isOnline.value) return // Bereits aktiv (Dummy-Check)
|
||||
scope.launch {
|
||||
// Sofort prüfen
|
||||
_isOnline.value = checkConnection()
|
||||
// Zweiter Check nach kurzer Wartezeit, um Start-Races zu glätten
|
||||
delay(3_000.milliseconds)
|
||||
_isOnline.value = checkConnection()
|
||||
// Danach im Intervall prüfen
|
||||
while (isActive) {
|
||||
_isOnline.value = checkConnection()
|
||||
delay(10_000.milliseconds) // Alle 10 Sekunden prüfen
|
||||
_isOnline.value = checkConnection()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private suspend fun checkConnection(): Boolean {
|
||||
return try {
|
||||
val response = client.get(NetworkConfig.baseUrl.trimEnd('/') + "/actuator/health/readiness")
|
||||
response.status.value in 200..299
|
||||
} catch (_: Exception) {
|
||||
false
|
||||
val base = NetworkConfig.baseUrl.trimEnd('/')
|
||||
// 1) readiness
|
||||
try {
|
||||
val r1 = client.get("$base/actuator/health/readiness")
|
||||
if (r1.status.value in 200..299) return true
|
||||
} catch (e: Exception) {
|
||||
// Debug-Log schlank halten
|
||||
println("[Connectivity] readiness failed: ${e.message}")
|
||||
}
|
||||
|
||||
// 2) health
|
||||
try {
|
||||
val r2 = client.get("$base/actuator/health")
|
||||
if (r2.status.value in 200..299) return true
|
||||
} catch (e: Exception) {
|
||||
println("[Connectivity] health failed: ${e.message}")
|
||||
}
|
||||
|
||||
// 3) public ping via gateway routing
|
||||
try {
|
||||
val r3 = client.get("$base/api/ping/simple")
|
||||
if (r3.status.value in 200..299) return true
|
||||
} catch (e: Exception) {
|
||||
println("[Connectivity] ping/simple failed: ${e.message}")
|
||||
}
|
||||
|
||||
return false
|
||||
}
|
||||
|
||||
fun stopTracking() {
|
||||
|
||||
+1
-1
@@ -100,6 +100,6 @@ class KtorWebSocketServerService(
|
||||
fun getPort(): Int = port
|
||||
|
||||
companion object {
|
||||
const val DEFAULT_PORT: Int = 8081
|
||||
const val DEFAULT_PORT: Int = 8090
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user