@@ -72,6 +72,7 @@ class Operator(client: NamespacedKubernetesClient? = null,
7272 val probeFailureThreshold: Int
7373 val probeTimeout: Int
7474 val startupProbeInitialDelay: Int
75+ val processMaxLifetime: Long
7576
7677 private val podSetCustomResourceDefinitionContext = CustomResourceDefinitionContext .Builder ()
7778 .withVersion(" v1alpha1" )
@@ -112,6 +113,19 @@ class Operator(client: NamespacedKubernetesClient? = null,
112113 this .probeFailureThreshold = readConfigValue(probeFailureThreshold, 0 , " SPO_PROBE_FAILURE_THRESHOLD" , String ::toInt)
113114 this .probeTimeout = readConfigValue(probeTimeout, 1 , " SPO_PROBE_TIMEOUT" , String ::toInt)
114115 this .startupProbeInitialDelay = readConfigValue(startupProbeInitialDelay, 60 , " SPO_STARTUP_PROBE_INITIAL_DELAY" , String ::toInt)
116+ this .processMaxLifetime = readConfigValue(null , - 1 , " SPO_PROCESS_MAX_LIFETIME" , String ::toLong)
117+ if (this .processMaxLifetime != - 1L ) {
118+ Timer ().schedule(this .processMaxLifetime * 60 * 1000 ) {
119+ logger.warn { " Max lifetime of process reached, preparing shutdown" }
120+ sendChannel.close();
121+ while (! channel.isClosedForReceive && ! channel.isEmpty && ! shinyProxyController.idle) {
122+ logger.warn { " Still processing events in queue, delaying shutdown" }
123+ Thread .sleep(250 )
124+ }
125+ logger.warn { " Queue is empty, exiting process" }
126+ exitProcess(1 );
127+ }
128+ }
115129
116130 val rootLogger = LoggerFactory .getILoggerFactory().getLogger(Logger .ROOT_LOGGER_NAME ) as Logger
117131 rootLogger.level = readConfigValue(logLevel, Level .DEBUG , " SPO_LOG_LEVEL" , { Level .toLevel(it) })
0 commit comments