Skip to content

Commit

Permalink
feat:Docker构建机支持拓展资源调度 TencentBlueKing#10162
Browse files Browse the repository at this point in the history
  • Loading branch information
sawyersong2 committed Apr 16, 2024
1 parent 67d5915 commit 6282aa2
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ class OpJobQuotaProjectResourceImpl @Autowired constructor(
createTime: String,
channelCode: String
): Result<Boolean> {
jobQuotaRedisUtils.restoreProjectJobTime(projectId, vmType, channelCode)
jobQuotaManagerService.clearRunningJobs(projectId, vmType, createTime, channelCode)
return Result(true)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,23 @@ class RunningJobsDao {
}
}

fun clearRunningJobs(
dslContext: DSLContext,
projectId: String,
vmType: JobQuotaVmType,
channelCode: String,
createTime: LocalDateTime
) {
with(TDispatchRunningJobs.T_DISPATCH_RUNNING_JOBS) {
dslContext.deleteFrom(this)
.where(PROJECT_ID.eq(projectId))
.and(VM_TYPE.eq(vmType.name))
.and(CHANNEL_CODE.eq(channelCode))
.and(CREATED_TIME.lessOrEqual(createTime))
.execute()
}
}

fun getProject(dslContext: DSLContext): Result<Record1<String>>? {
with(TDispatchRunningJobs.T_DISPATCH_RUNNING_JOBS) {
return dslContext.selectDistinct(PROJECT_ID).from(this).fetch()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,19 +31,22 @@ import com.tencent.devops.common.api.util.timestamp
import com.tencent.devops.common.pipeline.enums.ChannelCode
import com.tencent.devops.dispatch.dao.JobQuotaProjectDao
import com.tencent.devops.dispatch.dao.JobQuotaSystemDao
import com.tencent.devops.dispatch.dao.RunningJobsDao
import com.tencent.devops.dispatch.pojo.JobQuotaProject
import com.tencent.devops.dispatch.pojo.JobQuotaSystem
import com.tencent.devops.dispatch.pojo.enums.JobQuotaVmType
import org.jooq.DSLContext
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.stereotype.Service
import java.time.LocalDateTime
import java.time.format.DateTimeFormatter

@Service@Suppress("ALL")
class JobQuotaManagerService @Autowired constructor(
private val jobQuotaProjectDao: JobQuotaProjectDao,
private val dslContext: DSLContext,
private val runningJobsDao: RunningJobsDao,
private val jobQuotaSystemDao: JobQuotaSystemDao,
private val dslContext: DSLContext
private val jobQuotaProjectDao: JobQuotaProjectDao
) {
fun listProjectQuota(projectId: String?): List<JobQuotaProject> {
val record = jobQuotaProjectDao.list(dslContext, projectId)
Expand Down Expand Up @@ -219,4 +222,22 @@ class JobQuotaManagerService @Autowired constructor(
fun updateSystemQuota(jobQuotaVmType: JobQuotaVmType, jobQuota: JobQuotaSystem): Boolean {
return jobQuotaSystemDao.update(dslContext, jobQuota.channelCode, jobQuotaVmType, jobQuota)
}

/**
* 清理指定项目时间点的配额记录
*/
fun clearRunningJobs(
projectId: String,
vmType: JobQuotaVmType,
createTime: String,
channelCode: String = ChannelCode.BS.name
) {
runningJobsDao.clearRunningJobs(
dslContext = dslContext,
projectId = projectId,
vmType = vmType,
channelCode = channelCode,
createTime = LocalDateTime.parse(createTime, DateTimeFormatter.ISO_LOCAL_DATE_TIME)
)
}
}

0 comments on commit 6282aa2

Please sign in to comment.