| | |
| | | package com.zy.acs.conveyor.core.operation; |
| | | |
| | | import com.zy.acs.common.utils.News; |
| | | import com.zy.acs.conveyor.core.enums.ConveyorStateType; |
| | | import com.zy.acs.conveyor.core.properties.CtuOperationConfig; |
| | | import lombok.extern.slf4j.Slf4j; |
| | |
| | | // 自动注册所有操作处理器 |
| | | for (OperationHandler handler : handlers) { |
| | | handlerMap.put(handler.getType(), handler); |
| | | log.info("注册输送线操作处理器: {}", handler.getType()); |
| | | News.info("注册输送线操作处理器: {}", handler.getType()); |
| | | } |
| | | } |
| | | |
| | | public void execute(CtuOperationConfig config) { |
| | | OperationHandler handler = handlerMap.get(config.getType()); |
| | | if (handler == null) { |
| | | log.warn("未找到操作处理器: {}", config.getType()); |
| | | News.warn("未找到操作处理器: {}", config.getType()); |
| | | return; |
| | | } |
| | | |
| | | int retryCount = 0; |
| | | while (retryCount < config.getMaxRetries()) { |
| | | try { |
| | | handler.execute(config); |
| | | return; |
| | | } catch (Exception e) { |
| | | retryCount++; |
| | | if (retryCount >= config.getMaxRetries()) { |
| | | log.error("操作执行失败,已达到最大重试次数: {}", config.getType(), e); |
| | | } else { |
| | | log.warn("操作执行失败,正在重试({}/{})", |
| | | retryCount, config.getMaxRetries(), e); |
| | | try { |
| | | Thread.sleep(config.getRetryDelay()); |
| | | } catch (InterruptedException ie) { |
| | | Thread.currentThread().interrupt(); |
| | | log.error("重试休眠被中断", ie); |
| | | return; |
| | | } |
| | | } |
| | | } |
| | | try { |
| | | handler.execute(config); |
| | | } catch (Exception e) { |
| | | News.error("操作执行失败,等待下一周期重试: {}", config.getType(), e); |
| | | } |
| | | } |
| | | } |