-
Notifications
You must be signed in to change notification settings - Fork 202
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3379 from jsonwan/github_perf/cron
perf: 定时任务全量加载速度优化 #3363
- Loading branch information
Showing
23 changed files
with
833 additions
and
219 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
97 changes: 97 additions & 0 deletions
97
...-job-crontab/src/main/java/com/tencent/bk/job/crontab/model/dto/AddJobToQuartzResult.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
/* | ||
* Tencent is pleased to support the open source community by making BK-JOB蓝鲸智云作业平台 available. | ||
* | ||
* Copyright (C) 2021 THL A29 Limited, a Tencent company. All rights reserved. | ||
* | ||
* BK-JOB蓝鲸智云作业平台 is licensed under the MIT License. | ||
* | ||
* License for BK-JOB蓝鲸智云作业平台: | ||
* -------------------------------------------------------------------- | ||
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated | ||
* documentation files (the "Software"), to deal in the Software without restriction, including without limitation | ||
* the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and | ||
* to permit persons to whom the Software is furnished to do so, subject to the following conditions: | ||
* | ||
* The above copyright notice and this permission notice shall be included in all copies or substantial portions of | ||
* the Software. | ||
* | ||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO | ||
* THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF | ||
* CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS | ||
* IN THE SOFTWARE. | ||
*/ | ||
|
||
package com.tencent.bk.job.crontab.model.dto; | ||
|
||
import lombok.Data; | ||
|
||
/** | ||
* 添加任务到Quartz的结果 | ||
*/ | ||
@Data | ||
public class AddJobToQuartzResult { | ||
/** | ||
* 定时任务基本信息 | ||
*/ | ||
private CronJobBasicInfoDTO cronJobBasicInfo; | ||
/** | ||
* 是否成功 | ||
*/ | ||
private boolean success; | ||
/** | ||
* 提示信息 | ||
*/ | ||
private String message; | ||
/** | ||
* 异常信息 | ||
*/ | ||
private Exception exception; | ||
|
||
/** | ||
* 构造失败结果 | ||
* | ||
* @param cronJobBasicInfo 定时任务基本信息 | ||
* @param message 提示信息 | ||
* @return 失败结果 | ||
*/ | ||
public static AddJobToQuartzResult failResult(CronJobBasicInfoDTO cronJobBasicInfo, String message) { | ||
AddJobToQuartzResult result = new AddJobToQuartzResult(); | ||
result.setCronJobBasicInfo(cronJobBasicInfo); | ||
result.setSuccess(false); | ||
result.setMessage(message); | ||
return result; | ||
} | ||
|
||
/** | ||
* 构造失败结果 | ||
* | ||
* @param cronJobBasicInfo 定时任务基本信息 | ||
* @param message 提示信息 | ||
* @param exception 异常信息 | ||
* @return 失败结果 | ||
*/ | ||
public static AddJobToQuartzResult failResult(CronJobBasicInfoDTO cronJobBasicInfo, | ||
String message, | ||
Exception exception) { | ||
AddJobToQuartzResult result = new AddJobToQuartzResult(); | ||
result.setCronJobBasicInfo(cronJobBasicInfo); | ||
result.setSuccess(false); | ||
result.setMessage(message); | ||
result.setException(exception); | ||
return result; | ||
} | ||
|
||
/** | ||
* 构造成功结果 | ||
* | ||
* @param cronJobBasicInfo 定时任务基本信息 | ||
* @return 成功结果 | ||
*/ | ||
public static AddJobToQuartzResult successResult(CronJobBasicInfoDTO cronJobBasicInfo) { | ||
AddJobToQuartzResult result = new AddJobToQuartzResult(); | ||
result.setCronJobBasicInfo(cronJobBasicInfo); | ||
result.setSuccess(true); | ||
return result; | ||
} | ||
} |
119 changes: 119 additions & 0 deletions
119
...ervice-job-crontab/src/main/java/com/tencent/bk/job/crontab/model/dto/BatchAddResult.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,119 @@ | ||
/* | ||
* Tencent is pleased to support the open source community by making BK-JOB蓝鲸智云作业平台 available. | ||
* | ||
* Copyright (C) 2021 THL A29 Limited, a Tencent company. All rights reserved. | ||
* | ||
* BK-JOB蓝鲸智云作业平台 is licensed under the MIT License. | ||
* | ||
* License for BK-JOB蓝鲸智云作业平台: | ||
* -------------------------------------------------------------------- | ||
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated | ||
* documentation files (the "Software"), to deal in the Software without restriction, including without limitation | ||
* the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and | ||
* to permit persons to whom the Software is furnished to do so, subject to the following conditions: | ||
* | ||
* The above copyright notice and this permission notice shall be included in all copies or substantial portions of | ||
* the Software. | ||
* | ||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO | ||
* THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF | ||
* CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS | ||
* IN THE SOFTWARE. | ||
*/ | ||
|
||
package com.tencent.bk.job.crontab.model.dto; | ||
|
||
import lombok.Data; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.springframework.util.CollectionUtils; | ||
|
||
import java.util.ArrayList; | ||
import java.util.Collections; | ||
import java.util.HashMap; | ||
import java.util.List; | ||
import java.util.Map; | ||
|
||
/** | ||
* 定时任务批量添加到Quartz的结果 | ||
*/ | ||
@Slf4j | ||
@Data | ||
public class BatchAddResult { | ||
/** | ||
* 添加结果Map,key为定时任务ID,value为添加结果 | ||
*/ | ||
private Map<Long, AddJobToQuartzResult> resultMap; | ||
/** | ||
* 添加成功的任务数量 | ||
*/ | ||
private int successNum = 0; | ||
/** | ||
* 添加失败的任务数量 | ||
*/ | ||
private int failNum = 0; | ||
|
||
/** | ||
* 添加一个结果数据至批量结果 | ||
* | ||
* @param result 单个结果数据 | ||
*/ | ||
public void addResult(AddJobToQuartzResult result) { | ||
if (result == null) { | ||
return; | ||
} | ||
if (resultMap == null) { | ||
resultMap = new HashMap<>(); | ||
} | ||
CronJobBasicInfoDTO cronJobBasicInfo = result.getCronJobBasicInfo(); | ||
if (cronJobBasicInfo == null) { | ||
log.info("cronJobBasicInfo is null, ignore"); | ||
return; | ||
} | ||
resultMap.put(cronJobBasicInfo.getId(), result); | ||
if (result.isSuccess()) { | ||
successNum++; | ||
} else { | ||
failNum++; | ||
} | ||
} | ||
|
||
/** | ||
* 合并批量结果 | ||
* | ||
* @param batchAddResult 待合并的批量结果 | ||
*/ | ||
public void merge(BatchAddResult batchAddResult) { | ||
if (batchAddResult == null) { | ||
return; | ||
} | ||
if (CollectionUtils.isEmpty(batchAddResult.resultMap)) { | ||
return; | ||
} | ||
if (resultMap == null) { | ||
resultMap = new HashMap<>(batchAddResult.resultMap); | ||
} else { | ||
resultMap.putAll(batchAddResult.resultMap); | ||
} | ||
successNum += batchAddResult.successNum; | ||
failNum += batchAddResult.failNum; | ||
} | ||
|
||
/** | ||
* 获取批量添加失败的添加结果列表 | ||
* | ||
* @return 批量添加失败的添加结果列表 | ||
*/ | ||
public List<AddJobToQuartzResult> getFailedResultList() { | ||
if (failNum == 0) { | ||
return Collections.emptyList(); | ||
} | ||
List<AddJobToQuartzResult> failedResultList = new ArrayList<>(); | ||
for (Map.Entry<Long, AddJobToQuartzResult> entry : resultMap.entrySet()) { | ||
if (!entry.getValue().isSuccess()) { | ||
failedResultList.add(entry.getValue()); | ||
} | ||
} | ||
return failedResultList; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
55 changes: 55 additions & 0 deletions
55
...ice-job-crontab/src/main/java/com/tencent/bk/job/crontab/service/BatchCronJobService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
/* | ||
* Tencent is pleased to support the open source community by making BK-JOB蓝鲸智云作业平台 available. | ||
* | ||
* Copyright (C) 2021 THL A29 Limited, a Tencent company. All rights reserved. | ||
* | ||
* BK-JOB蓝鲸智云作业平台 is licensed under the MIT License. | ||
* | ||
* License for BK-JOB蓝鲸智云作业平台: | ||
* -------------------------------------------------------------------- | ||
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated | ||
* documentation files (the "Software"), to deal in the Software without restriction, including without limitation | ||
* the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and | ||
* to permit persons to whom the Software is furnished to do so, subject to the following conditions: | ||
* | ||
* The above copyright notice and this permission notice shall be included in all copies or substantial portions of | ||
* the Software. | ||
* | ||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO | ||
* THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF | ||
* CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS | ||
* IN THE SOFTWARE. | ||
*/ | ||
|
||
package com.tencent.bk.job.crontab.service; | ||
|
||
import com.tencent.bk.job.crontab.model.BatchUpdateCronJobReq; | ||
import com.tencent.bk.job.crontab.model.dto.BatchAddResult; | ||
import com.tencent.bk.job.crontab.model.dto.CronJobBasicInfoDTO; | ||
import com.tencent.bk.job.crontab.model.dto.NeedScheduleCronInfo; | ||
|
||
import java.util.List; | ||
|
||
public interface BatchCronJobService { | ||
|
||
/** | ||
* 批量添加定时任务到Quartz | ||
* | ||
* @param cronJobBasicInfoList 定时任务列表 | ||
* @return 批量添加结果 | ||
*/ | ||
BatchAddResult batchAddJobToQuartz(List<CronJobBasicInfoDTO> cronJobBasicInfoList); | ||
|
||
/** | ||
* 批量更新定时任务 | ||
* | ||
* @param username 用户名 | ||
* @param appId Job业务ID | ||
* @param batchUpdateCronJobReq 批量更新请求 | ||
* @return 更新结果数据 | ||
*/ | ||
NeedScheduleCronInfo batchUpdateCronJob(String username, | ||
Long appId, | ||
BatchUpdateCronJobReq batchUpdateCronJobReq); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.