Commit 961480e6 by guominglei

Merge remote-tracking branch 'origin/developer' into developer

parents 8edbcee1 8c195b02
*.class
*.iml
compiler.xml
encodings.xml
Maven_*.xml
misc.xml
modules.xml
Project_Default.xml
vcs.xml
workspace.xml
target
\ No newline at end of file
...@@ -32,7 +32,8 @@ public class MythJobScheduler implements InitializingBean, DisposableBean { ...@@ -32,7 +32,8 @@ public class MythJobScheduler implements InitializingBean, DisposableBean {
*/ */
@Override @Override
public void destroy() throws Exception { public void destroy() throws Exception {
this.jobScheduleHelper.doStop();
this.logScanHelper.doStop();
} }
/** /**
...@@ -42,8 +43,8 @@ public class MythJobScheduler implements InitializingBean, DisposableBean { ...@@ -42,8 +43,8 @@ public class MythJobScheduler implements InitializingBean, DisposableBean {
@Override @Override
public void afterPropertiesSet() throws Exception { public void afterPropertiesSet() throws Exception {
//启用扫描线程 //启用扫描线程
jobScheduleHelper.start(); this.jobScheduleHelper.start();
logScanHelper.start(); this.logScanHelper.start();
} }
} }
package com.byit.enums;
/**
* @description: 运行记录的枚举类
* @author huangfu
*/
public enum RunRecordingEnum {
RUN_FLOW_SUCCESS("1","工作流运行成功")
,RUN_FLOW_FAILURE("2","工作流运行失败")
,RUN_FLOW_RE_SUCCESS("3","补批成功")
,RUN_FLOW_RE_FAILURE("4","补批失败")
,RUN_FLOW_KILL("5","工作流进程被杀死")
,FLOW_STATUS_NOT_RUN("1","工作流未开始")
,FLOW_STATUS_RUN_ING("2","工作流运行中")
,FLOW_STATUS_IS_STOP("3","工作流被暂停")
,FLOW_STATUS_IS_END("4","工作流已经完结")
;
private String code;
private String message;
RunRecordingEnum(String code, String message) {
this.code = code;
this.message = message;
}
public String getCode() {
return code;
}
public String getMessage() {
return message;
}}
...@@ -320,6 +320,43 @@ public class JobScheduleHelper{ ...@@ -320,6 +320,43 @@ public class JobScheduleHelper{
scheduleThread.setDaemon(true); scheduleThread.setDaemon(true);
scheduleThread.start(); scheduleThread.start();
} }
public void doStop(){
this.jobInfoThreadToStop = true;
try {
TimeUnit.SECONDS.sleep(1);
} catch (InterruptedException e) {
e.printStackTrace( );
}
if (jobInfoThread.getState() != Thread.State.TERMINATED) {
jobInfoThread.interrupt();
try {
jobInfoThread.join();
} catch (InterruptedException e) {
e.printStackTrace( );
}
}
log.warn("---------------【任务节点节点扫描线程被注销】-----------------------");
this.scheduleThreadToStop = true;
try {
TimeUnit.SECONDS.sleep(1);
} catch (InterruptedException e) {
e.printStackTrace( );
}
if (scheduleThread.getState() != Thread.State.TERMINATED) {
scheduleThread.interrupt();
try {
scheduleThread.join();
} catch (InterruptedException e) {
e.printStackTrace( );
}
}
log.warn("---------------【排期表扫描线程被注销】-----------------------");
}
@Autowired @Autowired
public void setDataSource(DataSource dataSource) { public void setDataSource(DataSource dataSource) {
......
package com.byit.thread; package com.byit.thread;
import cn.hutool.core.collection.CollectionUtil; import cn.hutool.core.collection.CollectionUtil;
import com.byit.enums.RunRecordingEnum;
import com.byit.model.JobTaskRunLog; import com.byit.model.JobTaskRunLog;
import com.byit.model.RunRecording; import com.byit.model.RunRecording;
import com.byit.service.JobTaskRunLogService; import com.byit.service.JobTaskRunLogService;
...@@ -109,7 +110,43 @@ public class LogScanHelper { ...@@ -109,7 +110,43 @@ public class LogScanHelper {
e.printStackTrace(); e.printStackTrace();
}finally { }finally {
//释放资源 //释放资源
freedResource(conn,preparedStatement,connAutoCommit,virtualNodeScanIsStop); if(conn != null){
try {
conn.commit();
} catch (SQLException e) {
if(!virtualNodeScanIsStop){
log.error("--------------------【提交行锁出错】---------------------");
}
}
}
try {
if(conn != null){
conn.setAutoCommit(connAutoCommit);
}
} catch (SQLException e) {
if(!virtualNodeScanIsStop){
log.error("--------------------【恢复自动提交出错】---------------------");
}
}
if(preparedStatement != null){
try {
preparedStatement.close();
} catch (SQLException e) {
if(!notAlarmedNodeScanIsStop){
log.error("--------------------【关闭执行器出错】---------------------");
}
}
}
try {
conn.close();
} catch (SQLException e) {
if(!virtualNodeScanIsStop){
log.error("--------------------【关闭链接出错】---------------------");
}
}
} }
} }
...@@ -135,7 +172,6 @@ public class LogScanHelper { ...@@ -135,7 +172,6 @@ public class LogScanHelper {
conn.setAutoCommit(false); conn.setAutoCommit(false);
preparedStatement = conn.prepareStatement("SELECT * FROM JOB_LOCK WHERE LOCK_NAME = 'log_node_callback_lock' FOR UPDATE "); preparedStatement = conn.prepareStatement("SELECT * FROM JOB_LOCK WHERE LOCK_NAME = 'log_node_callback_lock' FOR UPDATE ");
preparedStatement.execute(); preparedStatement.execute();
System.out.println("--------------火球锁成功------------------" );
//查询的是失败的或者是已经结束的节点(完成的) //查询的是失败的或者是已经结束的节点(完成的)
List<JobTaskRunLog> jobTaskRunLogEndOrFailureNode = jobTaskRunLogService.findJobTaskRunLogEndOrFailureNode( ); List<JobTaskRunLog> jobTaskRunLogEndOrFailureNode = jobTaskRunLogService.findJobTaskRunLogEndOrFailureNode( );
if(CollectionUtil.isNotEmpty(jobTaskRunLogEndOrFailureNode)){ if(CollectionUtil.isNotEmpty(jobTaskRunLogEndOrFailureNode)){
...@@ -162,7 +198,7 @@ public class LogScanHelper { ...@@ -162,7 +198,7 @@ public class LogScanHelper {
successNodes.forEach(successNode ->{ successNodes.forEach(successNode ->{
String runId = successNode.getRunId( ); String runId = successNode.getRunId( );
Integer flowId = successNode.getFlowId( ); Integer flowId = successNode.getFlowId( );
runRecordingService.updateRunRecordingByFlowIdAndRunId(RunRecording.builder().runId(runId).flowId(flowId).flowRunResult("1").flowStatus("4").build()); runRecordingService.updateRunRecordingByFlowIdAndRunId(RunRecording.builder().runId(runId).flowId(flowId).flowRunResult(RunRecordingEnum.RUN_FLOW_SUCCESS.getCode()).flowStatus(RunRecordingEnum.FLOW_STATUS_IS_END.getCode()).build());
successNode.setAlertEnd("1"); successNode.setAlertEnd("1");
jobTaskRunLogService.updateJobTaskRunLog(successNode); jobTaskRunLogService.updateJobTaskRunLog(successNode);
}); });
...@@ -183,37 +219,22 @@ public class LogScanHelper { ...@@ -183,37 +219,22 @@ public class LogScanHelper {
}catch (Exception e){ }catch (Exception e){
e.printStackTrace(); e.printStackTrace();
}finally { }finally {
freedResource(conn,preparedStatement,connAutoCommit,notAlarmedNodeScanIsStop);
}
}
});
notAlarmedNodeScanThread.setName("myth-job#【LogScanHelper】#notAlarmedNodeScanThread");
notAlarmedNodeScanThread.setDaemon(true);
notAlarmedNodeScanThread.start();
}
/**
* 释放资源
* @param conn 数据库链接
* @param preparedStatement 执行器
* @param connAutoCommit 原来的提交状态
*/
private void freedResource(Connection conn,PreparedStatement preparedStatement,boolean connAutoCommit,boolean isStop){
if(conn != null){ if(conn != null){
try { try {
conn.commit(); conn.commit();
} catch (SQLException e) { } catch (SQLException e) {
if(!isStop){ if(!notAlarmedNodeScanIsStop){
log.error("--------------------【提交行锁出错】---------------------"); log.error("--------------------【提交行锁出错】---------------------");
} }
} }
} }
try { try {
assert conn != null; if(conn != null){
conn.setAutoCommit(connAutoCommit); conn.setAutoCommit(connAutoCommit);
}
} catch (SQLException e) { } catch (SQLException e) {
if(!isStop){ if(!notAlarmedNodeScanIsStop){
log.error("--------------------【恢复自动提交出错】---------------------"); log.error("--------------------【恢复自动提交出错】---------------------");
} }
} }
...@@ -222,7 +243,7 @@ public class LogScanHelper { ...@@ -222,7 +243,7 @@ public class LogScanHelper {
try { try {
preparedStatement.close(); preparedStatement.close();
} catch (SQLException e) { } catch (SQLException e) {
if(!isStop){ if(!notAlarmedNodeScanIsStop){
log.error("--------------------【关闭执行器出错】---------------------"); log.error("--------------------【关闭执行器出错】---------------------");
} }
} }
...@@ -231,12 +252,18 @@ public class LogScanHelper { ...@@ -231,12 +252,18 @@ public class LogScanHelper {
try { try {
conn.close(); conn.close();
} catch (SQLException e) { } catch (SQLException e) {
if(!isStop){ if(!notAlarmedNodeScanIsStop){
log.error("--------------------【关闭链接出错】---------------------"); log.error("--------------------【关闭链接出错】---------------------");
} }
} }
} }
}
});
notAlarmedNodeScanThread.setName("myth-job#【LogScanHelper】#notAlarmedNodeScanThread");
notAlarmedNodeScanThread.setDaemon(true);
notAlarmedNodeScanThread.start();
}
public void doStop(){ public void doStop(){
this.virtualNodeScanIsStop = true; this.virtualNodeScanIsStop = true;
...@@ -254,6 +281,7 @@ public class LogScanHelper { ...@@ -254,6 +281,7 @@ public class LogScanHelper {
e.printStackTrace( ); e.printStackTrace( );
} }
} }
log.warn("---------------【虚节点扫描线程被注销】-----------------------");
this.notAlarmedNodeScanIsStop = true; this.notAlarmedNodeScanIsStop = true;
try { try {
...@@ -269,6 +297,8 @@ public class LogScanHelper { ...@@ -269,6 +297,8 @@ public class LogScanHelper {
e.printStackTrace( ); e.printStackTrace( );
} }
} }
log.warn("---------------【日志扫描线程被注销】-----------------------");
} }
......
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