update - 解决多个任务同时操作同一个实例,出现的事务问题
This commit is contained in:
parent
eb3914a838
commit
f9069f9b1f
@ -10,7 +10,6 @@ import org.flowable.common.engine.impl.interceptor.Command;
|
||||
import org.flowable.common.engine.impl.interceptor.CommandConfig;
|
||||
import org.flowable.common.engine.impl.interceptor.CommandExecutor;
|
||||
|
||||
import static cn.axzo.workflow.core.common.code.FlowableEngineRespCode.ENGINE_ASYNC_COMMAND_EXECUTION_ERROR;
|
||||
import static cn.axzo.workflow.core.common.code.FlowableEngineRespCode.ENGINE_ASYNC_COMMAND_EXECUTION_RETRY_GIVE_UP;
|
||||
|
||||
/**
|
||||
@ -28,35 +27,31 @@ public class CustomRetryInterceptor extends AbstractCommandInterceptor {
|
||||
|
||||
@Override
|
||||
public <T> T execute(CommandConfig config, Command<T> command, CommandExecutor commandExecutor) {
|
||||
try {
|
||||
long waitTime = waitTimeInMs;
|
||||
int failedAttempts = 0;
|
||||
do {
|
||||
if (failedAttempts > 0) {
|
||||
log.warn("Waiting for {}ms before retrying the command.", waitTime);
|
||||
waitBeforeRetry(waitTime);
|
||||
waitTime *= waitIncreaseFactor;
|
||||
long waitTime = waitTimeInMs;
|
||||
int failedAttempts = 0;
|
||||
do {
|
||||
if (failedAttempts > 0) {
|
||||
log.warn("Waiting for {}ms before retrying the command.", waitTime);
|
||||
waitBeforeRetry(waitTime);
|
||||
waitTime *= waitIncreaseFactor;
|
||||
}
|
||||
|
||||
try {
|
||||
// try to execute the command
|
||||
if (AbstractCommand.class.isAssignableFrom(command.getClass())) {
|
||||
// 如果在以后,重试三次也不能解决的话, 可以利用这里的拿到的参数,重新自动构造CMD,并执行.
|
||||
log.info("traceId:{} Executing command params: {}", TraceUtil.traceId(),
|
||||
((AbstractCommand<T>) command).paramToJsonString());
|
||||
}
|
||||
return next.execute(config, command, commandExecutor);
|
||||
|
||||
try {
|
||||
// try to execute the command
|
||||
if (AbstractCommand.class.isAssignableFrom(command.getClass())) {
|
||||
// 如果在以后,重试三次也不能解决的话, 可以利用这里的拿到的参数,重新自动构造CMD,并执行.
|
||||
log.info("traceId:{} Executing command params: {}", TraceUtil.traceId(),
|
||||
((AbstractCommand<T>) command).paramToJsonString());
|
||||
}
|
||||
return next.execute(config, command, commandExecutor);
|
||||
} catch (PersistenceException e) {
|
||||
log.warn("Caught persistence exception: {}", e.getMessage(), e);
|
||||
}
|
||||
|
||||
} catch (PersistenceException e) {
|
||||
log.warn("Caught persistence exception: {}", e.getMessage(), e);
|
||||
}
|
||||
failedAttempts++;
|
||||
} while (failedAttempts <= numOfRetries);
|
||||
|
||||
failedAttempts++;
|
||||
} while (failedAttempts <= numOfRetries);
|
||||
} catch (Throwable e) {
|
||||
log.error("Caught exception: {}", e.getMessage(), e);
|
||||
throw new WorkflowEngineException(ENGINE_ASYNC_COMMAND_EXECUTION_ERROR, e.getMessage());
|
||||
}
|
||||
throw new WorkflowEngineException(ENGINE_ASYNC_COMMAND_EXECUTION_RETRY_GIVE_UP, String.valueOf(numOfRetries));
|
||||
}
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user