fix(测试跟踪): 测试计划定时任务兼容微服务之前版本

--bug=1022487 --user=赵勇 【定时任务】2.2.1版本升级到2.6.1版本,测试计划和接口场景的定时任务初始化报错,也没按时执行 https://www.tapd.cn/55049933/s/1332341
This commit is contained in:
chenjianxing 2023-02-07 16:23:42 +08:00 committed by jianxing
parent 2bea883de7
commit 93c3f5ed8a
3 changed files with 4 additions and 30 deletions

View File

@ -48,6 +48,7 @@ public class BaseScheduleService {
private final String API_SCENARIO_JOB = "io.metersphere.sechedule.ApiScenarioTestJob"; private final String API_SCENARIO_JOB = "io.metersphere.sechedule.ApiScenarioTestJob";
private final String API_SWAGGER_IMPORT_JOB = "io.metersphere.sechedule.SwaggerUrlImportJob"; private final String API_SWAGGER_IMPORT_JOB = "io.metersphere.sechedule.SwaggerUrlImportJob";
private final String TEST_PLAN_JOB = "io.metersphere.plan.job.TestPlanTestJob";
public void addSchedule(Schedule schedule) { public void addSchedule(Schedule schedule) {
schedule.setId(UUID.randomUUID().toString()); schedule.setId(UUID.randomUUID().toString());
@ -143,6 +144,7 @@ public class BaseScheduleService {
switch (group) { switch (group) {
case API_SCENARIO_TEST -> schedule.setJob(API_SCENARIO_JOB); case API_SCENARIO_TEST -> schedule.setJob(API_SCENARIO_JOB);
case SWAGGER_IMPORT -> schedule.setJob(API_SWAGGER_IMPORT_JOB); case SWAGGER_IMPORT -> schedule.setJob(API_SWAGGER_IMPORT_JOB);
case TEST_PLAN_TEST -> schedule.setJob(TEST_PLAN_JOB);
} }
} }

View File

@ -1,29 +0,0 @@
package io.metersphere.job.sechedule;
import io.metersphere.commons.utils.LogUtil;
import org.quartz.*;
public abstract class MsScheduleJob implements Job {
protected String resourceId;
protected String userId;
protected String expression;
@Override
public void execute(JobExecutionContext context) throws JobExecutionException {
JobKey jobKey = context.getTrigger().getJobKey();
JobDataMap jobDataMap = context.getJobDetail().getJobDataMap();
this.resourceId = jobDataMap.getString("resourceId");
this.userId = jobDataMap.getString("userId");
this.expression = jobDataMap.getString("expression");
LogUtil.info(jobKey.getGroup() + " Running: " + resourceId);
LogUtil.info("CronExpression: " + expression);
businessExecute(context);
}
abstract void businessExecute(JobExecutionContext context);
}

View File

@ -4,6 +4,7 @@ import io.metersphere.commons.constants.ReportTriggerMode;
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.request.RunTestPlanRequest; import io.metersphere.request.RunTestPlanRequest;
import io.metersphere.sechedule.MsScheduleJob;
import io.metersphere.service.PerformanceTestService; import io.metersphere.service.PerformanceTestService;
import org.quartz.JobExecutionContext; import org.quartz.JobExecutionContext;
import org.quartz.JobKey; import org.quartz.JobKey;
@ -18,7 +19,7 @@ public class PerformanceTestJob extends MsScheduleJob {
} }
@Override @Override
void businessExecute(JobExecutionContext context) { protected void businessExecute(JobExecutionContext context) {
RunTestPlanRequest request = new RunTestPlanRequest(); RunTestPlanRequest request = new RunTestPlanRequest();
request.setId(resourceId); request.setId(resourceId);
request.setUserId(userId); request.setUserId(userId);