@ -134,9 +134,13 @@ public class StateWheelExecuteThread extends BaseDaemonThread {
return ;
return ;
}
}
for ( Integer processInstanceId : processInstanceTimeoutCheckList ) {
for ( Integer processInstanceId : processInstanceTimeoutCheckList ) {
WorkflowExecuteRunnable workflowExecuteThread = processInstanceExecCacheManager . getByProcessInstanceId ( processInstanceId ) ;
try {
LoggerUtils . setWorkflowInstanceIdMDC ( processInstanceId ) ;
WorkflowExecuteRunnable workflowExecuteThread = processInstanceExecCacheManager . getByProcessInstanceId (
processInstanceId ) ;
if ( workflowExecuteThread = = null ) {
if ( workflowExecuteThread = = null ) {
logger . warn ( "Check workflow timeout failed, can not find workflowExecuteThread from cache manager, will remove this workflowInstance from check list" ) ;
logger . warn (
"Check workflow timeout failed, can not find workflowExecuteThread from cache manager, will remove this workflowInstance from check list" ) ;
processInstanceTimeoutCheckList . remove ( processInstanceId ) ;
processInstanceTimeoutCheckList . remove ( processInstanceId ) ;
continue ;
continue ;
}
}
@ -145,13 +149,20 @@ public class StateWheelExecuteThread extends BaseDaemonThread {
logger . warn ( "Check workflow timeout failed, the workflowInstance is null" ) ;
logger . warn ( "Check workflow timeout failed, the workflowInstance is null" ) ;
continue ;
continue ;
}
}
long timeRemain = DateUtils . getRemainTime ( processInstance . getStartTime ( ) , ( long ) processInstance . getTimeout ( ) * Constants . SEC_2_MINUTES_TIME_UNIT ) ;
long timeRemain = DateUtils . getRemainTime ( processInstance . getStartTime ( ) ,
( long ) processInstance . getTimeout ( )
* Constants . SEC_2_MINUTES_TIME_UNIT ) ;
if ( timeRemain < 0 ) {
if ( timeRemain < 0 ) {
logger . info ( "Workflow instance timeout, adding timeout event" ) ;
logger . info ( "Workflow instance timeout, adding timeout event" ) ;
addProcessTimeoutEvent ( processInstance ) ;
addProcessTimeoutEvent ( processInstance ) ;
processInstanceTimeoutCheckList . remove ( processInstance . getId ( ) ) ;
processInstanceTimeoutCheckList . remove ( processInstance . getId ( ) ) ;
logger . info ( "Workflow instance timeout, added timeout event" ) ;
logger . info ( "Workflow instance timeout, added timeout event" ) ;
}
}
} catch ( Exception ex ) {
logger . error ( "Check workflow instance timeout error" ) ;
} finally {
LoggerUtils . removeWorkflowInstanceIdMDC ( ) ;
}
}
}
}
}
@ -243,20 +254,26 @@ public class StateWheelExecuteThread extends BaseDaemonThread {
}
}
Optional < TaskInstance > taskInstanceOptional = workflowExecuteThread . getActiveTaskInstanceByTaskCode ( taskCode ) ;
Optional < TaskInstance > taskInstanceOptional = workflowExecuteThread . getActiveTaskInstanceByTaskCode ( taskCode ) ;
if ( ! taskInstanceOptional . isPresent ( ) ) {
if ( ! taskInstanceOptional . isPresent ( ) ) {
logger . warn ( "Check task instance timeout failed, can not get taskInstance from workflowExecuteThread, taskCode: {}"
logger . warn (
+ "will remove this check task" , taskCode ) ;
"Check task instance timeout failed, can not get taskInstance from workflowExecuteThread, taskCode: {}"
+ "will remove this check task" ,
taskCode ) ;
taskInstanceTimeoutCheckList . remove ( taskInstanceKey ) ;
taskInstanceTimeoutCheckList . remove ( taskInstanceKey ) ;
continue ;
continue ;
}
}
TaskInstance taskInstance = taskInstanceOptional . get ( ) ;
TaskInstance taskInstance = taskInstanceOptional . get ( ) ;
if ( TimeoutFlag . OPEN = = taskInstance . getTaskDefine ( ) . getTimeoutFlag ( ) ) {
if ( TimeoutFlag . OPEN = = taskInstance . getTaskDefine ( ) . getTimeoutFlag ( ) ) {
long timeRemain = DateUtils . getRemainTime ( taskInstance . getStartTime ( ) , ( long ) taskInstance . getTaskDefine ( ) . getTimeout ( ) * Constants . SEC_2_MINUTES_TIME_UNIT ) ;
long timeRemain = DateUtils . getRemainTime ( taskInstance . getStartTime ( ) ,
( long ) taskInstance . getTaskDefine ( ) . getTimeout ( )
* Constants . SEC_2_MINUTES_TIME_UNIT ) ;
if ( timeRemain < 0 ) {
if ( timeRemain < 0 ) {
logger . info ( "Task instance is timeout, adding task timeout event and remove the check" ) ;
logger . info ( "Task instance is timeout, adding task timeout event and remove the check" ) ;
addTaskTimeoutEvent ( taskInstance ) ;
addTaskTimeoutEvent ( taskInstance ) ;
taskInstanceTimeoutCheckList . remove ( taskInstanceKey ) ;
taskInstanceTimeoutCheckList . remove ( taskInstanceKey ) ;
}
}
}
}
} catch ( Exception ex ) {
logger . error ( "Check task timeout error, taskInstanceKey: {}" , taskInstanceKey , ex ) ;
} finally {
} finally {
LoggerUtils . removeWorkflowInstanceIdMDC ( ) ;
LoggerUtils . removeWorkflowInstanceIdMDC ( ) ;
}
}
@ -277,7 +294,8 @@ public class StateWheelExecuteThread extends BaseDaemonThread {
WorkflowExecuteRunnable workflowExecuteThread = processInstanceExecCacheManager . getByProcessInstanceId ( processInstanceId ) ;
WorkflowExecuteRunnable workflowExecuteThread = processInstanceExecCacheManager . getByProcessInstanceId ( processInstanceId ) ;
if ( workflowExecuteThread = = null ) {
if ( workflowExecuteThread = = null ) {
logger . warn ( "Task instance retry check failed, can not find workflowExecuteThread from cache manager, "
logger . warn (
"Task instance retry check failed, can not find workflowExecuteThread from cache manager, "
+ "will remove this check task" ) ;
+ "will remove this check task" ) ;
taskInstanceRetryCheckList . remove ( taskInstanceKey ) ;
taskInstanceRetryCheckList . remove ( taskInstanceKey ) ;
continue ;
continue ;
@ -315,6 +333,8 @@ public class StateWheelExecuteThread extends BaseDaemonThread {
addTaskRetryEvent ( taskInstance ) ;
addTaskRetryEvent ( taskInstance ) ;
taskInstanceRetryCheckList . remove ( taskInstanceKey ) ;
taskInstanceRetryCheckList . remove ( taskInstanceKey ) ;
}
}
} catch ( Exception ex ) {
logger . error ( "Check task retry error, taskInstanceKey: {}" , taskInstanceKey , ex ) ;
} finally {
} finally {
LoggerUtils . removeWorkflowInstanceIdMDC ( ) ;
LoggerUtils . removeWorkflowInstanceIdMDC ( ) ;
}
}
@ -349,6 +369,8 @@ public class StateWheelExecuteThread extends BaseDaemonThread {
continue ;
continue ;
}
}
addTaskStateChangeEvent ( taskInstance ) ;
addTaskStateChangeEvent ( taskInstance ) ;
} catch ( Exception ex ) {
logger . error ( "Task state check error, taskInstanceKey: {}" , taskInstanceKey , ex ) ;
} finally {
} finally {
LoggerUtils . removeWorkflowInstanceIdMDC ( ) ;
LoggerUtils . removeWorkflowInstanceIdMDC ( ) ;
}
}