feat(任务中心): 场景消息查询修改

This commit is contained in:
fit2-zhao 2021-06-16 19:12:52 +08:00 committed by fit2-zhao
parent ea1ae44dd3
commit 555a70d745
3 changed files with 43 additions and 40 deletions

View File

@ -980,48 +980,50 @@ public class ApiAutomationService {
private void run(Map<APIScenarioReportResult, RunModeDataDTO> map, RunScenarioRequest request, String serialReportId) {
// 开始选择执行模式
ExecutorService executorService = Executors.newFixedThreadPool(map.size());
if (request.getConfig() != null && request.getConfig().getMode().equals(RunModeConstants.SERIAL.toString())) {
// 开始串行执行
Thread thread = new Thread(new Runnable() {
@Override
public void run() {
List<String> reportIds = new LinkedList<>();
for (APIScenarioReportResult key : map.keySet()) {
apiScenarioReportMapper.insert(key);
reportIds.add(key.getId());
try {
Future<ApiScenarioReport> future = executorService.submit(new SerialScenarioExecTask(jMeterService, apiScenarioReportMapper, map.get(key), request));
ApiScenarioReport report = future.get();
// 如果开启失败结束执行则判断返回结果状态
if (request.getConfig().isOnSampleError()) {
if (report == null || !report.getStatus().equals("Success")) {
break;
if (map != null && map.size() > 0) {
ExecutorService executorService = Executors.newFixedThreadPool(map.size());
if (request.getConfig() != null && request.getConfig().getMode().equals(RunModeConstants.SERIAL.toString())) {
// 开始串行执行
Thread thread = new Thread(new Runnable() {
@Override
public void run() {
List<String> reportIds = new LinkedList<>();
for (APIScenarioReportResult key : map.keySet()) {
apiScenarioReportMapper.insert(key);
reportIds.add(key.getId());
try {
Future<ApiScenarioReport> future = executorService.submit(new SerialScenarioExecTask(jMeterService, apiScenarioReportMapper, map.get(key), request));
ApiScenarioReport report = future.get();
// 如果开启失败结束执行则判断返回结果状态
if (request.getConfig().isOnSampleError()) {
if (report == null || !report.getStatus().equals("Success")) {
break;
}
}
} catch (Exception e) {
LogUtil.error("执行终止:" + e.getMessage());
break;
}
} catch (Exception e) {
LogUtil.error("执行终止:" + e.getMessage());
break;
}
// 更新集成报告
if (StringUtils.isNotEmpty(serialReportId)) {
apiScenarioReportService.margeReport(serialReportId, reportIds);
map.clear();
}
}
// 更新集成报告
if (StringUtils.isNotEmpty(serialReportId)) {
apiScenarioReportService.margeReport(serialReportId, reportIds);
map.clear();
}
});
thread.start();
} else {
SqlSession sqlSession = sqlSessionFactory.openSession(ExecutorType.BATCH);
ApiScenarioReportMapper batchMapper = sqlSession.getMapper(ApiScenarioReportMapper.class);
// 开始并发执行
for (APIScenarioReportResult report : map.keySet()) {
//存储报告
batchMapper.insert(report);
executorService.submit(new ParallelScenarioExecTask(jMeterService, map.get(report), request));
}
});
thread.start();
} else {
SqlSession sqlSession = sqlSessionFactory.openSession(ExecutorType.BATCH);
ApiScenarioReportMapper batchMapper = sqlSession.getMapper(ApiScenarioReportMapper.class);
// 开始并发执行
for (APIScenarioReportResult report : map.keySet()) {
//存储报告
batchMapper.insert(report);
executorService.submit(new ParallelScenarioExecTask(jMeterService, map.get(report), request));
sqlSession.flushStatements();
}
sqlSession.flushStatements();
}
}

View File

@ -4,14 +4,14 @@
<select id="getTasks" resultType="io.metersphere.task.dto.TaskCenterDTO"
parameterType="java.lang.String">
SELECT tt.* FROM (
(select t.id,t.name,'SCENARIO' as executionModule, ifnull(t2.name,'LOCAL') as actuator, t1.`name` as executor,t.create_time as executionTime, t.trigger_mode as triggerMode ,t.execute_type as executionStatus
(select t.id,t.name,'SCENARIO' as executionModule, ifnull(t2.name,'LOCAL') as actuator, t1.`name` as executor,t.create_time as executionTime, t.trigger_mode as triggerMode ,t.status as executionStatus
from api_scenario_report t left join `user` t1 ON t.user_id = t1.id left join test_resource_pool t2 on t.actuator = t2.id
where to_days(FROM_UNIXTIME(t.create_time/1000))= to_days(now()) and t.execute_type !='Debug' and t.project_id= #{request.projectId}
<if test="request.triggerMode != null and request.triggerMode != ''">
and t.trigger_mode = #{request.triggerMode}
</if>
<if test="request.executionStatus != null and request.executionStatus != ''">
and t.execute_type = #{request.executionStatus}
and t.status = #{request.executionStatus}
</if>
)
UNION ALL

View File

@ -6,8 +6,9 @@
text-color="#fff"
active-text-color="#fff">
<el-menu-item onselectstart="return false">
<font-awesome-icon class="icon global" :icon="['fas', 'flag']"/>
<span @click="showTaskCenter">{{ $t('commons.task_center') }}</span>
<el-tooltip :content="$t('commons.task_center')">
<font-awesome-icon class="icon global" :icon="['fas', 'flag']" @click="showTaskCenter"/>
</el-tooltip>
</el-menu-item>
</el-menu>