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) { private void run(Map<APIScenarioReportResult, RunModeDataDTO> map, RunScenarioRequest request, String serialReportId) {
// 开始选择执行模式 // 开始选择执行模式
ExecutorService executorService = Executors.newFixedThreadPool(map.size()); if (map != null && map.size() > 0) {
if (request.getConfig() != null && request.getConfig().getMode().equals(RunModeConstants.SERIAL.toString())) { ExecutorService executorService = Executors.newFixedThreadPool(map.size());
// 开始串行执行 if (request.getConfig() != null && request.getConfig().getMode().equals(RunModeConstants.SERIAL.toString())) {
Thread thread = new Thread(new Runnable() { // 开始串行执行
@Override Thread thread = new Thread(new Runnable() {
public void run() { @Override
List<String> reportIds = new LinkedList<>(); public void run() {
for (APIScenarioReportResult key : map.keySet()) { List<String> reportIds = new LinkedList<>();
apiScenarioReportMapper.insert(key); for (APIScenarioReportResult key : map.keySet()) {
reportIds.add(key.getId()); apiScenarioReportMapper.insert(key);
try { reportIds.add(key.getId());
Future<ApiScenarioReport> future = executorService.submit(new SerialScenarioExecTask(jMeterService, apiScenarioReportMapper, map.get(key), request)); try {
ApiScenarioReport report = future.get(); 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")) { if (request.getConfig().isOnSampleError()) {
break; 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)) { thread.start();
apiScenarioReportService.margeReport(serialReportId, reportIds); } else {
map.clear(); 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();
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();
} }
} }

View File

@ -4,14 +4,14 @@
<select id="getTasks" resultType="io.metersphere.task.dto.TaskCenterDTO" <select id="getTasks" resultType="io.metersphere.task.dto.TaskCenterDTO"
parameterType="java.lang.String"> parameterType="java.lang.String">
SELECT tt.* FROM ( 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 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} 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 != ''"> <if test="request.triggerMode != null and request.triggerMode != ''">
and t.trigger_mode = #{request.triggerMode} and t.trigger_mode = #{request.triggerMode}
</if> </if>
<if test="request.executionStatus != null and request.executionStatus != ''"> <if test="request.executionStatus != null and request.executionStatus != ''">
and t.execute_type = #{request.executionStatus} and t.status = #{request.executionStatus}
</if> </if>
) )
UNION ALL UNION ALL

View File

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