mirror of
https://gitee.com/fit2cloud-feizhiyun/MeterSphere.git
synced 2024-12-05 05:29:29 +08:00
refactor: 定时任务使用一个线程同步执行
This commit is contained in:
parent
7c0cab89af
commit
841a85a4c9
@ -57,14 +57,7 @@ public class CleanHistoryJob {
|
||||
int size = 100;
|
||||
List<List<String>> batchList = splitList(sourceIds, size);
|
||||
|
||||
batchList.forEach(batch -> {
|
||||
Thread.startVirtualThread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
cleanupHistory(batch, limit);
|
||||
}
|
||||
});
|
||||
});
|
||||
batchList.forEach(batch -> cleanupHistory(batch, limit));
|
||||
}
|
||||
|
||||
private List<List<String>> splitList(List<String> list, int size) {
|
||||
|
@ -49,60 +49,56 @@ public class CleanUpReportJob {
|
||||
|
||||
for (int i = 0; i < pages; i++) {
|
||||
int start = i * 100;
|
||||
Thread.startVirtualThread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
List<Project> projects = baseProjectMapper.selectProjectByLimit(start,100);
|
||||
projects.forEach(project -> {
|
||||
ProjectApplicationExample applicationExample = new ProjectApplicationExample();
|
||||
//test_plan
|
||||
applicationExample.createCriteria().andProjectIdEqualTo(project.getId()).andTypeEqualTo(ProjectApplicationType.TEST_PLAN.TEST_PLAN_CLEAN_REPORT.name());
|
||||
List<ProjectApplication> testPlan = projectApplicationMapper.selectByExample(applicationExample);
|
||||
Map<String, String> map = new HashMap<>();
|
||||
if (CollectionUtils.isNotEmpty(testPlan)) {
|
||||
map.put(ProjectApplicationType.TEST_PLAN.TEST_PLAN_CLEAN_REPORT.name(), testPlan.get(0).getTypeValue());
|
||||
} else {
|
||||
map.put(ProjectApplicationType.TEST_PLAN.TEST_PLAN_CLEAN_REPORT.name(), "3M");
|
||||
}
|
||||
|
||||
//ui
|
||||
applicationExample.clear();
|
||||
applicationExample.createCriteria().andProjectIdEqualTo(project.getId()).andTypeEqualTo(ProjectApplicationType.UI.UI_CLEAN_REPORT.name());
|
||||
List<ProjectApplication> ui = projectApplicationMapper.selectByExample(applicationExample);
|
||||
if (CollectionUtils.isNotEmpty(ui)) {
|
||||
map.put(ProjectApplicationType.UI.UI_CLEAN_REPORT.name(), ui.get(0).getTypeValue());
|
||||
} else {
|
||||
map.put(ProjectApplicationType.UI.UI_CLEAN_REPORT.name(), "3M");
|
||||
}
|
||||
|
||||
//load_test
|
||||
applicationExample.clear();
|
||||
applicationExample.createCriteria().andProjectIdEqualTo(project.getId()).andTypeEqualTo(ProjectApplicationType.LOAD_TEST.LOAD_TEST_CLEAN_REPORT.name());
|
||||
List<ProjectApplication> loadTest = projectApplicationMapper.selectByExample(applicationExample);
|
||||
if (CollectionUtils.isNotEmpty(loadTest)) {
|
||||
map.put(ProjectApplicationType.LOAD_TEST.LOAD_TEST_CLEAN_REPORT.name(), loadTest.get(0).getTypeValue());
|
||||
} else {
|
||||
map.put(ProjectApplicationType.LOAD_TEST.LOAD_TEST_CLEAN_REPORT.name(), "3M");
|
||||
}
|
||||
|
||||
//api
|
||||
applicationExample.clear();
|
||||
applicationExample.createCriteria().andProjectIdEqualTo(project.getId()).andTypeEqualTo(ProjectApplicationType.API.API_CLEAN_REPORT.name());
|
||||
List<ProjectApplication> api = projectApplicationMapper.selectByExample(applicationExample);
|
||||
if (CollectionUtils.isNotEmpty(api)) {
|
||||
map.put(ProjectApplicationType.API.API_CLEAN_REPORT.name(), api.get(0).getTypeValue());
|
||||
} else {
|
||||
map.put(ProjectApplicationType.API.API_CLEAN_REPORT.name(), "3M");
|
||||
}
|
||||
|
||||
Map<String, BaseCleanUpReport> beansOfType = applicationContext.getBeansOfType(BaseCleanUpReport.class);
|
||||
beansOfType.forEach((k, v) -> {
|
||||
v.cleanReport(map, project.getId());
|
||||
});
|
||||
|
||||
});
|
||||
List<Project> projects = baseProjectMapper.selectProjectByLimit(start, 100);
|
||||
projects.forEach(project -> {
|
||||
ProjectApplicationExample applicationExample = new ProjectApplicationExample();
|
||||
//test_plan
|
||||
applicationExample.createCriteria().andProjectIdEqualTo(project.getId()).andTypeEqualTo(ProjectApplicationType.TEST_PLAN.TEST_PLAN_CLEAN_REPORT.name());
|
||||
List<ProjectApplication> testPlan = projectApplicationMapper.selectByExample(applicationExample);
|
||||
Map<String, String> map = new HashMap<>();
|
||||
if (CollectionUtils.isNotEmpty(testPlan)) {
|
||||
map.put(ProjectApplicationType.TEST_PLAN.TEST_PLAN_CLEAN_REPORT.name(), testPlan.get(0).getTypeValue());
|
||||
} else {
|
||||
map.put(ProjectApplicationType.TEST_PLAN.TEST_PLAN_CLEAN_REPORT.name(), "3M");
|
||||
}
|
||||
|
||||
//ui
|
||||
applicationExample.clear();
|
||||
applicationExample.createCriteria().andProjectIdEqualTo(project.getId()).andTypeEqualTo(ProjectApplicationType.UI.UI_CLEAN_REPORT.name());
|
||||
List<ProjectApplication> ui = projectApplicationMapper.selectByExample(applicationExample);
|
||||
if (CollectionUtils.isNotEmpty(ui)) {
|
||||
map.put(ProjectApplicationType.UI.UI_CLEAN_REPORT.name(), ui.get(0).getTypeValue());
|
||||
} else {
|
||||
map.put(ProjectApplicationType.UI.UI_CLEAN_REPORT.name(), "3M");
|
||||
}
|
||||
|
||||
//load_test
|
||||
applicationExample.clear();
|
||||
applicationExample.createCriteria().andProjectIdEqualTo(project.getId()).andTypeEqualTo(ProjectApplicationType.LOAD_TEST.LOAD_TEST_CLEAN_REPORT.name());
|
||||
List<ProjectApplication> loadTest = projectApplicationMapper.selectByExample(applicationExample);
|
||||
if (CollectionUtils.isNotEmpty(loadTest)) {
|
||||
map.put(ProjectApplicationType.LOAD_TEST.LOAD_TEST_CLEAN_REPORT.name(), loadTest.get(0).getTypeValue());
|
||||
} else {
|
||||
map.put(ProjectApplicationType.LOAD_TEST.LOAD_TEST_CLEAN_REPORT.name(), "3M");
|
||||
}
|
||||
|
||||
//api
|
||||
applicationExample.clear();
|
||||
applicationExample.createCriteria().andProjectIdEqualTo(project.getId()).andTypeEqualTo(ProjectApplicationType.API.API_CLEAN_REPORT.name());
|
||||
List<ProjectApplication> api = projectApplicationMapper.selectByExample(applicationExample);
|
||||
if (CollectionUtils.isNotEmpty(api)) {
|
||||
map.put(ProjectApplicationType.API.API_CLEAN_REPORT.name(), api.get(0).getTypeValue());
|
||||
} else {
|
||||
map.put(ProjectApplicationType.API.API_CLEAN_REPORT.name(), "3M");
|
||||
}
|
||||
|
||||
Map<String, BaseCleanUpReport> beansOfType = applicationContext.getBeansOfType(BaseCleanUpReport.class);
|
||||
beansOfType.forEach((k, v) -> {
|
||||
v.cleanReport(map, project.getId());
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user