Commit 8db192ba by guominglei

修改重跑时运行实例状态

parent 80d1a0f5
...@@ -4,10 +4,7 @@ import com.alibaba.fastjson.JSON; ...@@ -4,10 +4,7 @@ import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson.JSONObject;
import com.byit.dto.api.DeleteDto; import com.byit.dto.api.DeleteDto;
import com.byit.dto.plugin.*; import com.byit.dto.plugin.*;
import com.byit.enums.DagCheckEnum; import com.byit.enums.*;
import com.byit.enums.FlowPropertyEnum;
import com.byit.enums.NodePropertyEnum;
import com.byit.enums.ScheduleTypeEnum;
import com.byit.enums.plugin.PluginNodeTypeEnum; import com.byit.enums.plugin.PluginNodeTypeEnum;
import com.byit.job.utils.CronExpression; import com.byit.job.utils.CronExpression;
import com.byit.job.utils.CurrentUserUtils; import com.byit.job.utils.CurrentUserUtils;
...@@ -513,7 +510,9 @@ public class ApiFlowServiceImpl implements ApiFlowService { ...@@ -513,7 +510,9 @@ public class ApiFlowServiceImpl implements ApiFlowService {
} }
RunRecording newRunRecording = buildRunRecording(runRecording, triggerTime, reRunId, flow, userName); RunRecording newRunRecording = buildRunRecording(runRecording, triggerTime, reRunId, flow, userName);
runRecording.setFlowStatus(RunRecordingEnum.FLOW_STATUS_RUN_ING.getCode());
runRecording.setFlowRunResult(null);
runRecordingMapper.updateState(runRecording);
//生成新的工作流实例 //生成新的工作流实例
runRecordingMapper.saveRunRecording(newRunRecording); runRecordingMapper.saveRunRecording(newRunRecording);
jobTaskMapper.saveJobTasks(jobTaskList); jobTaskMapper.saveJobTasks(jobTaskList);
......
...@@ -205,4 +205,6 @@ public interface RunRecordingMapper { ...@@ -205,4 +205,6 @@ public interface RunRecordingMapper {
* @return * @return
*/ */
RunRecording findNewStatus(Integer flowId); RunRecording findNewStatus(Integer flowId);
int updateState(RunRecording runRecording);
} }
\ No newline at end of file
...@@ -90,50 +90,8 @@ public class StatusSnapshootThreadRunHelper extends BaseThreadRunHelper { ...@@ -90,50 +90,8 @@ public class StatusSnapshootThreadRunHelper extends BaseThreadRunHelper {
List<RunRecording> runRecordingList = runRecordingMapper.findByPreTime(new Date(preHourTime), flow.getFlowId()); List<RunRecording> runRecordingList = runRecordingMapper.findByPreTime(new Date(preHourTime), flow.getFlowId());
//判断是否存在过去一个小时的和未完成的工作流实例 //判断是否存在过去一个小时的和未完成的工作流实例
if(null != runRecordingList && runRecordingList.size() > 0){ if(null != runRecordingList && runRecordingList.size() > 0){
//如果存在,记录快照 //处理未完成和过去一个小时的工作流实例
runRecordingList.forEach(runRecording -> { buildUnFinish(runRecordingList, flowStatusSnapshootList, flowStatusSnapshoot, flow);
FlowStatusSnapshoot hourFlowStatusSnapshoot = new FlowStatusSnapshoot();
BeanUtils.copyProperties(flowStatusSnapshoot, hourFlowStatusSnapshoot);
//判断运行状态
if(StringUtils.isEmpty(runRecording.getFlowStatus())){
//如果为空设置为未运行
hourFlowStatusSnapshoot.setFlowStatus(1);
}else if (runRecording.getFlowStatus().equals("1") || runRecording.getFlowStatus().equals("2") || runRecording.getFlowStatus().equals("3")){
hourFlowStatusSnapshoot.setFlowStatus(Integer.valueOf(runRecording.getFlowStatus()));
}else if (runRecording.getFlowStatus().equals("4")){
switch (runRecording.getFlowRunResult()){
case "1" :
case "3" : hourFlowStatusSnapshoot.setFlowStatus(4); break;
case "2" :
case "4" : hourFlowStatusSnapshoot.setFlowStatus(5); break;
case "5" : hourFlowStatusSnapshoot.setFlowStatus(6); break;
default : hourFlowStatusSnapshoot.setFlowStatus(5); break;
}
}else {
//如果没在判断之内,设置为未运行
hourFlowStatusSnapshoot.setFlowStatus(1);
}
//获取运行实例下各类状态的节点数目
StatisticData nodeStatistic = jobTaskRunLogMapper.findStatisticDataByRunIdAndFlowId(runRecording.getRunId(), flow.getFlowId());
//判断是否存在节点的运行日志
//存在节点运行日志
if (nodeStatistic != null){
int sum = nodeStatistic.getFail() + nodeStatistic.getSuccess() + nodeStatistic.getRunIng() + nodeStatistic.getKill();
if(flow.getFlowNodeCount() > sum){
hourFlowStatusSnapshoot.setUnstartNode(flow.getFlowNodeCount() - sum);
}else {
hourFlowStatusSnapshoot.setUnstartNode(0);
}
hourFlowStatusSnapshoot.setRuningNode(nodeStatistic.getRunIng());
hourFlowStatusSnapshoot.setSuccessNode(nodeStatistic.getSuccess());
hourFlowStatusSnapshoot.setFailNode(nodeStatistic.getFail());
hourFlowStatusSnapshoot.setKillNode(nodeStatistic.getKill());
}else {
//不存在节点的运行日志
hourFlowStatusSnapshoot.setUnstartNode(flow.getFlowNodeCount());
}
flowStatusSnapshootList.add(hourFlowStatusSnapshoot);
});
}else { }else {
//如果不存在实例,获取上一个小时的运行快照保存 //如果不存在实例,获取上一个小时的运行快照保存
LocalDateTime preHourLocalDateTime = localDateTime.minusHours(1); LocalDateTime preHourLocalDateTime = localDateTime.minusHours(1);
...@@ -169,6 +127,62 @@ public class StatusSnapshootThreadRunHelper extends BaseThreadRunHelper { ...@@ -169,6 +127,62 @@ public class StatusSnapshootThreadRunHelper extends BaseThreadRunHelper {
return (60 - LocalTime.now().getMinute()) * 60 * 1000L; return (60 - LocalTime.now().getMinute()) * 60 * 1000L;
} }
/**
* 功能描述 处理过去一小时和未完成的工作流的快照
* @author gml
* @date 2020-05-08 10:20
* @param runRecordingList
* @param flowStatusSnapshootList
* @param flowStatusSnapshoot
* @return void
*/
private void buildUnFinish(List<RunRecording> runRecordingList, List<FlowStatusSnapshoot> flowStatusSnapshootList, FlowStatusSnapshoot flowStatusSnapshoot, Flow flow){
//如果存在,记录快照
runRecordingList.forEach(runRecording -> {
FlowStatusSnapshoot hourFlowStatusSnapshoot = new FlowStatusSnapshoot();
BeanUtils.copyProperties(flowStatusSnapshoot, hourFlowStatusSnapshoot);
//判断运行状态
if(StringUtils.isEmpty(runRecording.getFlowStatus())){
//如果为空设置为未运行
hourFlowStatusSnapshoot.setFlowStatus(1);
}else if (runRecording.getFlowStatus().equals("1") || runRecording.getFlowStatus().equals("2") || runRecording.getFlowStatus().equals("3")){
hourFlowStatusSnapshoot.setFlowStatus(Integer.valueOf(runRecording.getFlowStatus()));
}else if (runRecording.getFlowStatus().equals("4")){
switch (runRecording.getFlowRunResult()){
case "1" :
case "3" : hourFlowStatusSnapshoot.setFlowStatus(4); break;
case "2" :
case "4" : hourFlowStatusSnapshoot.setFlowStatus(5); break;
case "5" : hourFlowStatusSnapshoot.setFlowStatus(6); break;
default : hourFlowStatusSnapshoot.setFlowStatus(5); break;
}
}else {
//如果没在判断之内,设置为未运行
hourFlowStatusSnapshoot.setFlowStatus(1);
}
//获取运行实例下各类状态的节点数目
StatisticData nodeStatistic = jobTaskRunLogMapper.findStatisticDataByRunIdAndFlowId(runRecording.getRunId(), flow.getFlowId());
//判断是否存在节点的运行日志
//存在节点运行日志
if (nodeStatistic != null){
int sum = nodeStatistic.getFail() + nodeStatistic.getSuccess() + nodeStatistic.getRunIng() + nodeStatistic.getKill();
if(flow.getFlowNodeCount() > sum){
hourFlowStatusSnapshoot.setUnstartNode(flow.getFlowNodeCount() - sum);
}else {
hourFlowStatusSnapshoot.setUnstartNode(0);
}
hourFlowStatusSnapshoot.setRuningNode(nodeStatistic.getRunIng());
hourFlowStatusSnapshoot.setSuccessNode(nodeStatistic.getSuccess());
hourFlowStatusSnapshoot.setFailNode(nodeStatistic.getFail());
hourFlowStatusSnapshoot.setKillNode(nodeStatistic.getKill());
}else {
//不存在节点的运行日志
hourFlowStatusSnapshoot.setUnstartNode(flow.getFlowNodeCount());
}
flowStatusSnapshootList.add(hourFlowStatusSnapshoot);
});
}
@Override @Override
public DataSource getDataSource() { public DataSource getDataSource() {
......
...@@ -588,5 +588,9 @@ ...@@ -588,5 +588,9 @@
where run_id = #{runId,jdbcType=VARCHAR} where run_id = #{runId,jdbcType=VARCHAR}
and flow_name = #{flowName,jdbcType=VARCHAR} and flow_name = #{flowName,jdbcType=VARCHAR}
</update> </update>
<update id="updateState" parameterType="com.byit.model.RunRecording">
update run_recording set flow_status = #{flowStatus},flow_run_result = #{flowRunResult}
where recording_id = #{recordingId,jdbcType=INTEGER}
</update>
</mapper> </mapper>
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment