update(REQ-2364) - 对引擎内的处理命令时的非 FlowableException 日志降级

This commit is contained in:
wangli 2024-05-21 09:59:57 +08:00
parent 4af7e2a7a3
commit 3e4d0644e0
3 changed files with 67 additions and 0 deletions

View File

@ -1,6 +1,7 @@
package cn.axzo.workflow.core.conf;
import cn.axzo.workflow.core.engine.behavior.CustomActivityBehaviorFactory;
import cn.axzo.workflow.core.engine.cmd.CustomCommandContextFactory;
import cn.axzo.workflow.core.engine.id.DistributedTimeBasedIdGenerator;
import cn.axzo.workflow.core.engine.job.AsyncAbortProcessInstanceHandler;
import cn.axzo.workflow.core.engine.job.AsyncApproveTaskJobHandler;
@ -68,6 +69,7 @@ public class FlowableConfiguration {
configuration.setDefaultFailedJobWaitTime(30);
configuration.setAsyncFailedJobWaitTime(30);
configuration.setCustomAsyncRunnableExecutionExceptionHandlers(Lists.newArrayList(new CustomAsyncRunnableExecutionExceptionHandler()));
configuration.setCommandContextFactory(new CustomCommandContextFactory());
};
}

View File

@ -0,0 +1,44 @@
package cn.axzo.workflow.core.engine.cmd;
import cn.axzo.workflow.core.common.exception.WorkflowEngineException;
import org.flowable.common.engine.api.FlowableException;
import org.flowable.common.engine.api.FlowableOptimisticLockingException;
import org.flowable.common.engine.impl.interceptor.Command;
import org.flowable.common.engine.impl.interceptor.CommandContext;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* TODO
*
* @author wangli
* @since 2024/5/21 09:46
*/
public class CustomCommandContext extends CommandContext {
private static final Logger LOGGER = LoggerFactory.getLogger(CommandContext.class);
public CustomCommandContext(Command<?> command) {
super(command);
}
@Override
protected void logException() {
if (exception instanceof FlowableException && !((FlowableException) exception).isLogged()) {
return;
}
if (exception instanceof FlowableOptimisticLockingException) {
// reduce log level, as normally we're not interested in logging this exception
LOGGER.debug("Optimistic locking exception : {}", exception.getMessage(), exception);
} else if (exception instanceof FlowableException && ((FlowableException) exception).isReduceLogLevel()) {
// reduce log level, because this may have been caused because of job deletion due to cancelActiviti="true"
LOGGER.info("Error while closing command context", exception);
} else if (exception instanceof WorkflowEngineException) {
LOGGER.warn("Workflow error while closing command context", exception);
} else {
LOGGER.error("Error while closing command context", exception);
}
}
}

View File

@ -0,0 +1,21 @@
package cn.axzo.workflow.core.engine.cmd;
import org.flowable.common.engine.impl.interceptor.Command;
import org.flowable.common.engine.impl.interceptor.CommandContext;
import org.flowable.common.engine.impl.interceptor.CommandContextFactory;
/**
* TODO
*
* @author wangli
* @since 2024/5/21 09:45
*/
public class CustomCommandContextFactory extends CommandContextFactory {
@Override
public CommandContext createCommandContext(Command<?> cmd) {
CommandContext commandContext = new CustomCommandContext(cmd);
commandContext.setSessionFactories(sessionFactories);
return commandContext;
}
}