mirror of
https://gitee.com/fit2cloud-feizhiyun/MeterSphere.git
synced 2024-12-02 12:09:13 +08:00
refactor(项目设置): 定时清理测试报告
This commit is contained in:
parent
bba03a8aeb
commit
9aa75913e9
@ -3,7 +3,6 @@ package io.metersphere.job.sechedule;
|
|||||||
import io.metersphere.base.domain.Project;
|
import io.metersphere.base.domain.Project;
|
||||||
import io.metersphere.commons.constants.ScheduleGroup;
|
import io.metersphere.commons.constants.ScheduleGroup;
|
||||||
import io.metersphere.commons.utils.CommonBeanFactory;
|
import io.metersphere.commons.utils.CommonBeanFactory;
|
||||||
import io.metersphere.commons.utils.DateUtils;
|
|
||||||
import io.metersphere.commons.utils.LogUtil;
|
import io.metersphere.commons.utils.LogUtil;
|
||||||
import io.metersphere.dto.ProjectConfig;
|
import io.metersphere.dto.ProjectConfig;
|
||||||
import io.metersphere.service.ProjectApplicationService;
|
import io.metersphere.service.ProjectApplicationService;
|
||||||
@ -15,6 +14,7 @@ import org.quartz.JobKey;
|
|||||||
import org.quartz.TriggerKey;
|
import org.quartz.TriggerKey;
|
||||||
import java.time.LocalDate;
|
import java.time.LocalDate;
|
||||||
import java.time.ZoneId;
|
import java.time.ZoneId;
|
||||||
|
import java.util.function.BiConsumer;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author lyh
|
* @author lyh
|
||||||
@ -41,17 +41,16 @@ public class CleanUpReportJob extends MsScheduleJob {
|
|||||||
if (project == null) {
|
if (project == null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
ProjectConfig config = projectApplicationService.getProjectConfig(project.getId());
|
ProjectConfig config = projectApplicationService.getProjectConfig(project.getId());
|
||||||
try {
|
try {
|
||||||
if (BooleanUtils.isTrue(config.getCleanTrackReport())) {
|
if (BooleanUtils.isTrue(config.getCleanTrackReport())) {
|
||||||
this.cleanUpTrackReport(config.getCleanTrackReportExpr());
|
this.doCleanUp(projectService::cleanUpTrackReport, config.getCleanTrackReportExpr());
|
||||||
}
|
}
|
||||||
if (BooleanUtils.isTrue(config.getCleanApiReport())) {
|
if (BooleanUtils.isTrue(config.getCleanApiReport())) {
|
||||||
this.cleanUpApiReport(config.getCleanApiReportExpr());
|
this.doCleanUp(projectService::cleanUpApiReport, config.getCleanApiReportExpr());
|
||||||
}
|
}
|
||||||
if (BooleanUtils.isTrue(config.getCleanLoadReport())) {
|
if (BooleanUtils.isTrue(config.getCleanLoadReport())) {
|
||||||
this.cleanUpLoadReport(config.getCleanLoadReportExpr());
|
this.doCleanUp(projectService::cleanUpLoadReport, config.getCleanLoadReportExpr());
|
||||||
}
|
}
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
LogUtil.error("clean up report error.");
|
LogUtil.error("clean up report error.");
|
||||||
@ -68,31 +67,12 @@ public class CleanUpReportJob extends MsScheduleJob {
|
|||||||
return new TriggerKey(projectId, ScheduleGroup.CLEAN_UP_REPORT.name());
|
return new TriggerKey(projectId, ScheduleGroup.CLEAN_UP_REPORT.name());
|
||||||
}
|
}
|
||||||
|
|
||||||
private void cleanUpTrackReport(String expr) {
|
private void doCleanUp(BiConsumer<Long, String> func, String expr) {
|
||||||
long time = getCleanDate(expr);
|
long time = getCleanDate(expr);
|
||||||
if (time == 0) {
|
if (time == 0) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
LogUtil.info("clean up track plan report before: " + DateUtils.getTimeString(time) + ", resourceId : " + resourceId);
|
func.accept(time, resourceId);
|
||||||
projectService.cleanUpTrackReport(time, resourceId);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void cleanUpApiReport(String expr) {
|
|
||||||
long time = getCleanDate(expr);
|
|
||||||
if (time == 0) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
LogUtil.info("clean up api report before: " + DateUtils.getTimeString(time) + ", resourceId : " + resourceId);
|
|
||||||
projectService.cleanUpApiReport(time, resourceId);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void cleanUpLoadReport(String expr) {
|
|
||||||
long time = getCleanDate(expr);
|
|
||||||
if (time == 0) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
LogUtil.info("clean up load report before: " + DateUtils.getTimeString(time) + ", resourceId : " + resourceId);
|
|
||||||
projectService.cleanUpLoadReport(time, resourceId);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private long getCleanDate(String expr) {
|
private long getCleanDate(String expr) {
|
||||||
|
@ -16,10 +16,7 @@ import io.metersphere.base.mapper.ext.ExtUserGroupMapper;
|
|||||||
import io.metersphere.base.mapper.ext.ExtUserMapper;
|
import io.metersphere.base.mapper.ext.ExtUserMapper;
|
||||||
import io.metersphere.commons.constants.*;
|
import io.metersphere.commons.constants.*;
|
||||||
import io.metersphere.commons.exception.MSException;
|
import io.metersphere.commons.exception.MSException;
|
||||||
import io.metersphere.commons.utils.CommonBeanFactory;
|
import io.metersphere.commons.utils.*;
|
||||||
import io.metersphere.commons.utils.LogUtil;
|
|
||||||
import io.metersphere.commons.utils.ServiceUtils;
|
|
||||||
import io.metersphere.commons.utils.SessionUtils;
|
|
||||||
import io.metersphere.controller.request.AddProjectRequest;
|
import io.metersphere.controller.request.AddProjectRequest;
|
||||||
import io.metersphere.controller.request.ProjectRequest;
|
import io.metersphere.controller.request.ProjectRequest;
|
||||||
import io.metersphere.controller.request.ScheduleRequest;
|
import io.metersphere.controller.request.ScheduleRequest;
|
||||||
@ -920,6 +917,7 @@ public class ProjectService {
|
|||||||
if (StringUtils.isBlank(projectId)) {
|
if (StringUtils.isBlank(projectId)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
LogUtil.info("clean up track plan report before: " + DateUtils.getTimeString(time) + ", resourceId : " + projectId);
|
||||||
testPlanReportService.cleanUpReport(time, projectId);
|
testPlanReportService.cleanUpReport(time, projectId);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -927,6 +925,7 @@ public class ProjectService {
|
|||||||
if (StringUtils.isBlank(projectId)) {
|
if (StringUtils.isBlank(projectId)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
LogUtil.info("clean up api report before: " + DateUtils.getTimeString(time) + ", resourceId : " + projectId);
|
||||||
apiScenarioReportService.cleanUpReport(time, projectId);
|
apiScenarioReportService.cleanUpReport(time, projectId);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -934,6 +933,7 @@ public class ProjectService {
|
|||||||
if (StringUtils.isBlank(projectId)) {
|
if (StringUtils.isBlank(projectId)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
LogUtil.info("clean up load report before: " + DateUtils.getTimeString(time) + ", resourceId : " + projectId);
|
||||||
performanceReportService.cleanUpReport(time, projectId);
|
performanceReportService.cleanUpReport(time, projectId);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user