@@ -25,6 +25,7 @@ import com.fasterxml.jackson.databind.ObjectMapper
2525import com.fasterxml.jackson.module.kotlin.registerKotlinModule
2626import eu.openanalytics.shinyproxyoperator.crd.ShinyProxy
2727import eu.openanalytics.shinyproxyoperator.crd.ShinyProxyInstance
28+ import kotlinx.coroutines.delay
2829import mu.KotlinLogging
2930import okhttp3.OkHttpClient
3031import okhttp3.Request
@@ -46,21 +47,33 @@ class RecyclableChecker(
4647
4748 data class Response (@JsonProperty(" isRecyclable" ) val isRecyclable : Boolean , @JsonProperty(" activeConnections" ) val activeConnections : Int )
4849
49- override fun isInstanceRecyclable (shinyProxy : ShinyProxy , shinyProxyInstance : ShinyProxyInstance ): Boolean {
50+ override suspend fun isInstanceRecyclable (shinyProxy : ShinyProxy , shinyProxyInstance : ShinyProxyInstance ): Boolean {
5051 val pods = podRetriever.getShinyProxyPods(shinyProxy, shinyProxyInstance)
5152
5253 for (pod in pods) {
5354 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
55+ try {
56+ val podIP: String? = pod.status.podIP
57+ if (podIP == null ) {
58+ // no response received, try to check again
59+ logger.warn { " ${shinyProxy.logPrefix(shinyProxyInstance)} no ip found during recyclable check" }
60+ delay(500 )
61+ continue
62+ }
63+ val resp = checkServer(pod.status.podIP)
64+ if (resp == null ) {
65+ // no response received, try to check again
66+ logger.warn { " ${shinyProxy.logPrefix(shinyProxyInstance)} unreachable for recyclable check (using ${pod.status.podIP} )" }
67+ delay(500 )
68+ continue
69+ }
70+ if (! resp.isRecyclable) {
71+ logger.info { " ${shinyProxy.logPrefix(shinyProxyInstance)} Replica is not recyclable." }
72+ return false
73+ }
74+ } catch (e: Throwable ) {
75+ logger.warn(e) { " ${shinyProxy.logPrefix(shinyProxyInstance)} exception during recyclable check" }
76+ delay(500 )
6477 }
6578 }
6679 }
0 commit comments