yrenat commented on code in PR #6046:
URL: https://github.com/apache/texera/pull/6046#discussion_r3524871354
##########
computing-unit-managing-service/src/main/scala/org/apache/texera/service/resource/ComputingUnitManagingResource.scala:
##########
@@ -69,6 +70,73 @@ object ComputingUnitManagingResource {
.getInstance()
.createDSLContext()
+ def terminateIdleKubernetesComputingUnits(): Int = {
+ if (
+ !KubernetesConfig.kubernetesComputingUnitEnabled ||
+ KubernetesConfig.computingUnitIdleTimeoutMinutes <= 0
+ ) {
+ return 0
+ }
+
+ val now = new Timestamp(System.currentTimeMillis())
+ val cutoff = new Timestamp(
+ now.getTime - KubernetesConfig.computingUnitIdleTimeoutMinutes * 60 *
1000
+ )
+ val activeStatuses = Seq(Short.box(0), Short.box(1), Short.box(2))
+
+ withTransaction(context) { ctx =>
+ val cuDao = new WorkflowComputingUnitDao(ctx.configuration())
+ ctx
+ .selectFrom(WORKFLOW_COMPUTING_UNIT)
+ .where(
+ WORKFLOW_COMPUTING_UNIT.TYPE
+ .eq(WorkflowComputingUnitTypeEnum.kubernetes)
+ .and(WORKFLOW_COMPUTING_UNIT.TERMINATE_TIME.isNull)
+ )
+ .fetchInto(classOf[WorkflowComputingUnit])
+ .asScala
+ .count { unit =>
+ val cuid = unit.getCuid
+ val hasActiveExecution = ctx.fetchExists(
+ ctx
+ .selectOne()
+ .from(WORKFLOW_EXECUTIONS)
+ .where(
+ WORKFLOW_EXECUTIONS.CUID
+ .eq(cuid)
+ .and(WORKFLOW_EXECUTIONS.STATUS.in(activeStatuses: _*))
+ )
+ )
+ val latestUpdateTime = ctx
+
.select(org.jooq.impl.DSL.max(WORKFLOW_EXECUTIONS.LAST_UPDATE_TIME))
+ .from(WORKFLOW_EXECUTIONS)
+ .where(WORKFLOW_EXECUTIONS.CUID.eq(cuid))
+ .fetchOne(0, classOf[Timestamp])
+ val latestStartTime = ctx
+ .select(org.jooq.impl.DSL.max(WORKFLOW_EXECUTIONS.STARTING_TIME))
Review Comment:
done
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]