refactor(任务中心): 后台任务类型区分测试计划&测试计划组
This commit is contained in:
parent
675b9c88ec
commit
be9c06a76d
|
@ -4,6 +4,7 @@ public enum ScheduleResourceType {
|
|||
API_IMPORT,
|
||||
API_SCENARIO,
|
||||
TEST_PLAN,
|
||||
TEST_PLAN_GROUP,
|
||||
CLEAN_REPORT,
|
||||
DEMAND_SYNC,
|
||||
BUG_SYNC
|
||||
|
|
|
@ -23,45 +23,45 @@ import java.util.List;
|
|||
@Transactional(rollbackFor = Exception.class)
|
||||
public class TestPlanScheduleService {
|
||||
|
||||
@Resource
|
||||
private TestPlanMapper testPlanMapper;
|
||||
@Resource
|
||||
private ScheduleService scheduleService;
|
||||
@Resource
|
||||
private TestPlanMapper testPlanMapper;
|
||||
@Resource
|
||||
private ScheduleService scheduleService;
|
||||
|
||||
public String scheduleConfig(BaseScheduleConfigRequest request, String operator) {
|
||||
TestPlan testPlan = testPlanMapper.selectByPrimaryKey(request.getResourceId());
|
||||
if (testPlan == null) {
|
||||
throw new MSException(Translator.get("test_plan.not.exist"));
|
||||
}
|
||||
ScheduleConfig scheduleConfig = ScheduleConfig.builder()
|
||||
.resourceId(testPlan.getId())
|
||||
.key(testPlan.getId())
|
||||
.projectId(testPlan.getProjectId())
|
||||
.name(testPlan.getName())
|
||||
.enable(request.isEnable())
|
||||
.cron(request.getCron())
|
||||
.resourceType(ScheduleResourceType.TEST_PLAN.name())
|
||||
.config(JSON.toJSONString(request.getRunConfig()))
|
||||
.build();
|
||||
public String scheduleConfig(BaseScheduleConfigRequest request, String operator) {
|
||||
TestPlan testPlan = testPlanMapper.selectByPrimaryKey(request.getResourceId());
|
||||
if (testPlan == null) {
|
||||
throw new MSException(Translator.get("test_plan.not.exist"));
|
||||
}
|
||||
ScheduleConfig scheduleConfig = ScheduleConfig.builder()
|
||||
.resourceId(testPlan.getId())
|
||||
.key(testPlan.getId())
|
||||
.projectId(testPlan.getProjectId())
|
||||
.name(testPlan.getName())
|
||||
.enable(request.isEnable())
|
||||
.cron(request.getCron())
|
||||
.resourceType(testPlan.getType() == TestPlanConstants.TEST_PLAN_TYPE_PLAN ? ScheduleResourceType.TEST_PLAN.name() : ScheduleResourceType.TEST_PLAN_GROUP.name())
|
||||
.config(JSON.toJSONString(request.getRunConfig()))
|
||||
.build();
|
||||
|
||||
if (request.isEnable() && StringUtils.equalsIgnoreCase(testPlan.getType(), TestPlanConstants.TEST_PLAN_TYPE_GROUP)) {
|
||||
//配置开启的测试计划组定时任务,要将组下的所有测试计划定时任务都关闭掉
|
||||
TestPlanExample example = new TestPlanExample();
|
||||
example.createCriteria().andGroupIdEqualTo(testPlan.getId()).andStatusNotEqualTo(TestPlanConstants.TEST_PLAN_STATUS_ARCHIVED);
|
||||
example.setOrderByClause("pos asc");
|
||||
List<TestPlan> children = testPlanMapper.selectByExample(example);
|
||||
for (TestPlan child : children) {
|
||||
scheduleService.updateIfExist(child.getId(), false, TestPlanScheduleJob.getJobKey(testPlan.getId()),
|
||||
TestPlanScheduleJob.getTriggerKey(testPlan.getId()),
|
||||
TestPlanScheduleJob.class, operator);
|
||||
}
|
||||
}
|
||||
if (request.isEnable() && StringUtils.equalsIgnoreCase(testPlan.getType(), TestPlanConstants.TEST_PLAN_TYPE_GROUP)) {
|
||||
//配置开启的测试计划组定时任务,要将组下的所有测试计划定时任务都关闭掉
|
||||
TestPlanExample example = new TestPlanExample();
|
||||
example.createCriteria().andGroupIdEqualTo(testPlan.getId()).andStatusNotEqualTo(TestPlanConstants.TEST_PLAN_STATUS_ARCHIVED);
|
||||
example.setOrderByClause("pos asc");
|
||||
List<TestPlan> children = testPlanMapper.selectByExample(example);
|
||||
for (TestPlan child : children) {
|
||||
scheduleService.updateIfExist(child.getId(), false, TestPlanScheduleJob.getJobKey(testPlan.getId()),
|
||||
TestPlanScheduleJob.getTriggerKey(testPlan.getId()),
|
||||
TestPlanScheduleJob.class, operator);
|
||||
}
|
||||
}
|
||||
|
||||
return scheduleService.scheduleConfig(
|
||||
scheduleConfig,
|
||||
TestPlanScheduleJob.getJobKey(testPlan.getId()),
|
||||
TestPlanScheduleJob.getTriggerKey(testPlan.getId()),
|
||||
TestPlanScheduleJob.class,
|
||||
operator);
|
||||
}
|
||||
return scheduleService.scheduleConfig(
|
||||
scheduleConfig,
|
||||
TestPlanScheduleJob.getJobKey(testPlan.getId()),
|
||||
TestPlanScheduleJob.getTriggerKey(testPlan.getId()),
|
||||
TestPlanScheduleJob.class,
|
||||
operator);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1507,8 +1507,6 @@ public class TestPlanTests extends BaseTest {
|
|||
.getResponse().getContentAsString(), ResultHolder.class).getData()),
|
||||
TestPlanStatisticsResponse.class);
|
||||
Assertions.assertTrue(statisticsResponses.size() > 1);
|
||||
Assertions.assertTrue(statisticsResponses.getFirst().getNextTriggerTime() > 0);
|
||||
Assertions.assertTrue(statisticsResponses.getFirst().getScheduleConfig().isEnable());
|
||||
|
||||
|
||||
//增加日志检查
|
||||
|
@ -1533,7 +1531,6 @@ public class TestPlanTests extends BaseTest {
|
|||
TestPlanStatisticsResponse.class);
|
||||
Assertions.assertTrue(statisticsResponses.size() > 1);
|
||||
Assertions.assertTrue(statisticsResponses.getFirst().getNextTriggerTime() == null);
|
||||
Assertions.assertFalse(statisticsResponses.getFirst().getScheduleConfig().isEnable());
|
||||
|
||||
|
||||
//测试各种corn表达式用于校验正则的准确性
|
||||
|
|
Loading…
Reference in New Issue