Skip to content

Commit

Permalink
feat: 执行引擎任务调度配额限制 TencentBlueKing#261
Browse files Browse the repository at this point in the history
  • Loading branch information
wangyu096 committed Jun 21, 2024
1 parent 94d369b commit 5bdffc2
Showing 1 changed file with 12 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -81,22 +81,32 @@ public RunningJobResourceQuotaManager(StringRedisTemplate redisTemplate,
}

public void addJob(String appCode, ResourceScope resourceScope, long jobInstanceId) {
long startTime = System.currentTimeMillis();
String resourceScopeZSetKey = buildResourceScopeRunningJobZSetKey(resourceScope);
long currentTimestamp = System.currentTimeMillis();
redisTemplate.opsForZSet().add(resourceScopeZSetKey, String.valueOf(jobInstanceId), currentTimestamp);
if (StringUtils.isNotEmpty(appCode)) {
String appZSetKey = buildAppRunningJobZSetKey(appCode);
redisTemplate.opsForZSet().add(appZSetKey, String.valueOf(jobInstanceId), currentTimestamp);
}
long cost = System.currentTimeMillis() - startTime;
if (log.isDebugEnabled()) {
log.debug("Add job to RunningJobResourceQuotaCache cost : {} ms", cost);
}
}

public void removeJob(String appCode, ResourceScope resourceScope, long jobInstanceId) {
long startTime = System.currentTimeMillis();
String resourceScopeZSetKey = buildResourceScopeRunningJobZSetKey(resourceScope);
redisTemplate.opsForZSet().remove(resourceScopeZSetKey, String.valueOf(jobInstanceId));
if (StringUtils.isNotEmpty(appCode)) {
String appZSetKey = buildAppRunningJobZSetKey(appCode);
redisTemplate.opsForZSet().remove(appZSetKey, String.valueOf(jobInstanceId));
}
long cost = System.currentTimeMillis() - startTime;
if (log.isDebugEnabled()) {
log.debug("Remove job from RunningJobResourceQuotaCache cost : {} ms", cost);
}
}

/**
Expand All @@ -113,8 +123,8 @@ public ResourceQuotaCheckResultEnum checkResourceQuotaLimit(String appCode, Reso
boolean isJobFrom3rdApp = StringUtils.isNotEmpty(appCode);

List<String> keyList = new ArrayList<>();
keyList.add("job:execute:running:job:resource:scope:" + resourceScope.getResourceScopeUniqueId());
keyList.add(isJobFrom3rdApp ? "job:execute:running:job:app:" + appCode : "None");
keyList.add(buildResourceScopeRunningJobZSetKey(resourceScope));
keyList.add(isJobFrom3rdApp ? buildAppRunningJobZSetKey(appCode) : "None");

long resourceScopeLimit = runningJobResourceQuotaStore.getQuotaLimitByResourceScope(resourceScope);

Expand Down

0 comments on commit 5bdffc2

Please sign in to comment.