Commit 24cd6ee5 by huangfusuper

增加实例结束回调

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