Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FlowExecutor 异常优化 #41

Open
taotao365s opened this issue Jul 24, 2023 · 0 comments
Open

FlowExecutor 异常优化 #41

taotao365s opened this issue Jul 24, 2023 · 0 comments

Comments

@taotao365s
Copy link

private Slot doExecute(String chainId, Object param, String requestId, Class<?>[] contextBeanClazzArray, Object[] contextBeanArray,
			Integer slotIndex, InnerChainTypeEnum innerChainType) {
		//....

		Chain chain = null;
		try {
			chain = FlowBus.getChain(chainId);

			if (ObjectUtil.isNull(chain)) {
				String errorMsg = StrUtil.format("couldn't find chain with the id[{}]", chainId);
				throw new ChainNotFoundException(errorMsg);
			}
			// 执行chain
			chain.execute(slotIndex);
		}
		catch (ChainEndException e) {
			if (ObjectUtil.isNotNull(chain)) {
				String warnMsg = StrUtil.format("chain[{}] execute end on slot[{}]", chain.getChainId(), slotIndex);
				LOG.warn(warnMsg);
			}
		}
		catch (Exception e) {
			if (ObjectUtil.isNotNull(chain)) {
				String errMsg = StrUtil.format("chain[{}] execute error on slot[{}]", chain.getChainId(), slotIndex);
				if (BooleanUtil.isTrue(liteflowConfig.getPrintExecutionLog())) {
					LOG.error(errMsg, e);
				}
				else {
					LOG.error(errMsg);
				}
			}
			else {
				if (BooleanUtil.isTrue(liteflowConfig.getPrintExecutionLog())) {
					LOG.error(e.getMessage(), e);
				}
				else {
					LOG.error(e.getMessage());
				}
			}

			// 如果是正常流程需要把异常设置到slot的exception属性里
			// 如果是隐式流程,则需要设置到隐式流程的exception属性里
			if (innerChainType.equals(InnerChainTypeEnum.NONE)) {
				slot.setException(e);
			}
			else {
				slot.setSubException(chainId, e);
			}
		}
		finally {
			if (innerChainType.equals(InnerChainTypeEnum.NONE)) {
				slot.printStep();
				DataBus.releaseSlot(slotIndex);
				LFLoggerManager.removeRequestId();
			}
		}

catch (Exception e) 能否增加配置,异常部分继续往上抛?在不同公司或项目中,往往会有各种各样的异常

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant