@@ -50,30 +50,36 @@ class RecyclableChecker(
5050 val pods = podRetriever.getShinyProxyPods(shinyProxy, shinyProxyInstance)
5151
5252 for (pod in pods) {
53- val url = " http://${pod.status.podIP} :9090/actuator/recyclable"
54- val request = Request .Builder ()
55- .url(url)
56- .build()
57-
58- val body = try {
59- client.newCall(request).execute().body?.string()
60- } catch (e: IOException ) {
61- logger.warn { " ${shinyProxy.logPrefix(shinyProxyInstance)} unreachable for recyclable check (using ${url} )" }
62- // server unreachable -> do not delete it yet
63- return false
64- }
65- if (body == null ) {
66- // server unreachable -> do not delete it yet
67- return false
68- }
69- val resp = objectMapper.readValue(body, Response ::class .java)
70- if (! resp.isRecyclable) {
71- logger.info { " ${shinyProxy.logPrefix(shinyProxyInstance)} Replica has ${resp.activeConnections} open websocket connections" }
72- return false
53+ for (i in 1 .. 5 ) {
54+ val resp = checkServer(pod.status.podIP)
55+ if (resp == null ) {
56+ // no response received, try to check again
57+ logger.warn { " ${shinyProxy.logPrefix(shinyProxyInstance)} unreachable for recyclable check (using ${pod.status.podIP} )" }
58+ Thread .sleep(500 )
59+ continue
60+ }
61+ if (! resp.isRecyclable) {
62+ logger.info { " ${shinyProxy.logPrefix(shinyProxyInstance)} Replica is not recyclable." }
63+ return false
64+ }
7365 }
7466 }
7567
7668 return true
7769 }
7870
71+ private fun checkServer (ip : String ): Response ? {
72+ val url = " http://${ip} :9090/actuator/recyclable"
73+ val request = Request .Builder ()
74+ .url(url)
75+ .build()
76+
77+ val body = try {
78+ client.newCall(request).execute().body?.string() ? : return null
79+ } catch (e: IOException ) {
80+ return null
81+ }
82+ return objectMapper.readValue(body, Response ::class .java)
83+ }
84+
7985}
0 commit comments