Commit 24cd6ee5 by huangfusuper

增加实例结束回调

parent 4037ac2c
package com.byit.event;
import com.byit.model.RunRecording;
import org.springframework.context.ApplicationEvent;
/**
......@@ -9,20 +10,20 @@ import org.springframework.context.ApplicationEvent;
public class EndFlowEvent extends ApplicationEvent {
private static final long serialVersionUID = 2874836396737756384L;
private Integer flowId;
private final RunRecording runRecording;
/**
* 创建工作流完结的事件
*
* @param source the object on which the event initially occurred (never {@code null})
* @param flowId 工作流id
* @param runRecording 工作流实例
*/
public EndFlowEvent(Object source,Integer flowId) {
public EndFlowEvent(Object source,RunRecording runRecording) {
super(source);
this.flowId = flowId;
this.runRecording = runRecording;
}
public Integer getFlowId() {
return flowId;
public RunRecording getRunRecording() {
return runRecording;
}
}
package com.byit.event;
import com.byit.model.RunRecording;
import org.springframework.context.ApplicationEvent;
/**
......@@ -9,20 +10,21 @@ import org.springframework.context.ApplicationEvent;
*/
public class FlowScanEndEvent extends ApplicationEvent {
private Integer flowId;
private static final long serialVersionUID = -6549668138353259198L;
private final RunRecording runRecording;
/**
* 创建工作流添加进实例表完毕后的事件
*
* @param source the object on which the event initially occurred (never {@code null})
* @param flowId 工作流id
* @param runRecording 工作流
*/
public FlowScanEndEvent(Object source,Integer flowId) {
public FlowScanEndEvent(Object source,RunRecording runRecording) {
super(source);
this.flowId = flowId;
this.runRecording = runRecording;
}
public Integer getFlowId() {
return flowId;
public RunRecording getRunRecording() {
return runRecording;
}
}
\ No newline at end of file
......@@ -32,7 +32,7 @@ public class FlowEventListener {
public void flowScanEndEventListener(FlowScanEndEvent flowScanEndEvent){
log.info("-----------监听到事件{},工作流添加进实例完成事件-------",flowScanEndEvent);
Flow flow = Flow.builder()
.flowId(flowScanEndEvent.getFlowId())
.flowId(flowScanEndEvent.getRunRecording().getFlowId())
.scanMark(FlowPropertyEnum.NOT_SCAN.getCode())
.build();
flowService.updateByIdSelective(flow);
......@@ -46,9 +46,11 @@ public class FlowEventListener {
public void flowEndEventListener(EndFlowEvent endFlowEvent){
log.info("-----------监听到事件{},工作流实例完成事件-------",endFlowEvent);
Flow flow = Flow.builder()
.flowId(endFlowEvent.getFlowId())
.flowId(endFlowEvent.getRunRecording().getFlowId())
.scanMark(FlowPropertyEnum.SCAN.getCode())
.build();
flowService.updateByIdSelective(flow);
}
}
......@@ -129,7 +129,7 @@ public class RunNodeServiceImpl implements RunNodeServer, ApplicationEventPublis
e.printStackTrace();
}
updateFlow(flow);
applicationEventPublisher.publishEvent(new FlowScanEndEvent(this,flow.getFlowId()));
applicationEventPublisher.publishEvent(new FlowScanEndEvent(this,build));
log.info("-------saveRunRecAndTaskAndUpdate end-----------【运行结束】-----------------");
......
package com.byit.service.mapservice.impl;
import cn.hutool.core.collection.CollectionUtil;
import com.byit.dto.RunRecordingWrapped;
import com.byit.enums.EmailEnum;
import com.byit.enums.FlowPropertyEnum;
import com.byit.enums.RunRecordingEnum;
......@@ -9,6 +10,8 @@ import com.byit.event.EndFlowEvent;
import com.byit.model.*;
import com.byit.service.*;
import com.byit.service.mapservice.RunRecordingAndLogService;
import com.byit.strategy.InstanceRunTheLifeCycleCallback;
import com.byit.util.SpringUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.context.ApplicationEventPublisher;
......@@ -17,9 +20,7 @@ import org.springframework.stereotype.Service;
import java.net.InetAddress;
import java.net.UnknownHostException;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.*;
import java.util.stream.Collectors;
/**
......@@ -88,7 +89,7 @@ public class RunRecordingAndLogServiceImpl implements RunRecordingAndLogService,
runRecording.setIsAlarm(EmailEnum.IS_ALARM_NO.getCode());
runRecordingService.updateRunRecordingById(runRecording);
//执行工作流的完成事件
applicationEventPublisher.publishEvent(new EndFlowEvent(this,runRecording.getFlowId()));
applicationEventPublisher.publishEvent(new EndFlowEvent(this,runRecording));
virtualTasks.forEach(virtualTask -> {
Integer mapFlowId = virtualTask.getMapFlowId();
......@@ -150,6 +151,14 @@ public class RunRecordingAndLogServiceImpl implements RunRecordingAndLogService,
runRecordingService.updateRunRecordingById(virtualRunRecording);
}
Map<String, InstanceRunTheLifeCycleCallback> beansOfType = SpringUtil.getBeansOfType(InstanceRunTheLifeCycleCallback.class);
Set<Map.Entry<String, InstanceRunTheLifeCycleCallback>> entries = beansOfType.entrySet();
//回调生命周期
for (Map.Entry<String, InstanceRunTheLifeCycleCallback> entry : entries) {
log.info("-------------【开始回调周期{}后置】---------------",entry.getKey());
entry.getValue().postProcessBeforeInitialization(runRecording);
}
});
//删除task里面的数据
......
......@@ -10,7 +10,9 @@ import com.byit.model.JobTaskRunLogWithBLOBs;
import com.byit.model.RunRecording;
import com.byit.service.JobTaskRunLogService;
import com.byit.service.RunRecordingService;
import com.byit.strategy.InstanceRunTheLifeCycleCallback;
import com.byit.thread.BaseThreadRunHelper;
import com.byit.util.SpringUtil;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.context.ApplicationEventPublisher;
......@@ -20,6 +22,8 @@ import org.springframework.stereotype.Component;
import javax.sql.DataSource;
import java.util.Date;
import java.util.List;
import java.util.Map;
import java.util.Set;
/**
* 完结实例的线程
......@@ -72,17 +76,14 @@ public class ClosingExampleThreadRunHelper extends BaseThreadRunHelper implement
runRecording.setIsAlarm(EmailEnum.IS_ALARM_NO.getCode());
runRecording.setEndTime(new Date());
runRecordingService.updateRunRecordingById(runRecording);
applicationEventPublisher.publishEvent(new EndFlowEvent(this,flowId));
/*if (StringUtils.isNotBlank(runRecording.getReRunId())) {
String reRunId = runRecording.getReRunId();
Integer flowId1 = runRecording.getFlowId();
RunRecording runRecordingByFlowIdAndRunId = runRecordingService.findRunRecordingByFlowIdAndRunId(flowId1, reRunId);
runRecordingByFlowIdAndRunId.setIsAlarm(EmailEnum.IS_ALARM_NO.getCode());
runRecordingByFlowIdAndRunId.setEndTime(new Date());
runRecordingByFlowIdAndRunId.setFlowStatus(RunRecordingEnum.FLOW_STATUS_IS_END.getCode());
runRecordingService.updateRunRecordingById(runRecordingByFlowIdAndRunId);
}*/
applicationEventPublisher.publishEvent(new EndFlowEvent(this,runRecording));
Map<String, InstanceRunTheLifeCycleCallback> beansOfType = SpringUtil.getBeansOfType(InstanceRunTheLifeCycleCallback.class);
Set<Map.Entry<String, InstanceRunTheLifeCycleCallback>> entries = beansOfType.entrySet();
//回调生命周期
for (Map.Entry<String, InstanceRunTheLifeCycleCallback> entry : entries) {
log.info("-------------【开始回调周期{}后置】---------------",entry.getKey());
entry.getValue().postProcessBeforeInitialization(runRecording);
}
}
});
return UNIVERSAL_WAIT_TIME;
......
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