diff --git a/README.md b/README.md index 7a04e44..0aa69d4 100644 --- a/README.md +++ b/README.md @@ -90,6 +90,12 @@ susdt是一套全部开源的快速开发平台,毫无保留给个人及企业 ## Authenticator 动态码登录 +租赁订单交付间隔见`ruoyi-admin/src/main/resources/application-rental.yml`的`rental.delivery`: +`dispatch-interval-ms`默认3000,`push-interval-ms`默认2000;环境变量分别为 +`RENT_DELIVERY_DISPATCH_INTERVAL_MS`、`RENT_DELIVERY_PUSH_INTERVAL_MS`,范围500~60000毫秒。 +修改后重启服务端。正常在线、无积压且RPC及时返回时目标约10秒内接单,链上调用、快照过期和积压会额外耗时。 +日志`orderAgeMs`表示下单到分配,`taskAgeMs`表示任务创建到推送;Agent另记录签发至接收及预检查耗时。 + 保留密码和 Google 账号登录,新增六位动态码登录及个人中心绑定/解绑。部署前执行 `sql/totp_auth.sql` 并配置 `TOTP_ENCRYPTION_KEY`,详见 [部署与使用说明](docs/totp-login.md)。 ## susdt前后端分离交流群 diff --git a/ruoyi-admin/src/main/resources/application-rental.yml b/ruoyi-admin/src/main/resources/application-rental.yml index 721baa7..a10bbad 100644 --- a/ruoyi-admin/src/main/resources/application-rental.yml +++ b/ruoyi-admin/src/main/resources/application-rental.yml @@ -5,6 +5,11 @@ rental: master-key: ${RENT_MASTER_KEY:ZA+5tLy20rbLxsMEvVm7Ow9hl2qtAPD3nmiK1Tf52NA=} master-key-version: ${RENT_MASTER_KEY_VERSION:v1} confirmations: ${RENT_CONFIRMATIONS:19} + # 正常在线、无排队且RPC及时返回时,调度+推送等待约0~5秒,目标10秒左右接单。 + # 均为上轮执行完成后的等待时间;链上查询耗时不包含在间隔中。修改后重启服务端。 + delivery: + dispatch-interval-ms: ${RENT_DELIVERY_DISPATCH_INTERVAL_MS:3000} + push-interval-ms: ${RENT_DELIVERY_PUSH_INTERVAL_MS:2000} payment: # 新增表见sql/rent_topup_init.sql;支付库先执行sql/payment_topup_upgrade.sql。 enabled: ${RENT_PAYMENT_ENABLED:false} diff --git a/ruoyi-system/src/main/java/com/ruoyi/system/rental/RentalSocket.java b/ruoyi-system/src/main/java/com/ruoyi/system/rental/RentalSocket.java index d7eabec..8e5d24a 100644 --- a/ruoyi-system/src/main/java/com/ruoyi/system/rental/RentalSocket.java +++ b/ruoyi-system/src/main/java/com/ruoyi/system/rental/RentalSocket.java @@ -20,6 +20,7 @@ import java.util.concurrent.ConcurrentHashMap; @Component @ConditionalOnProperty(name = "rental.enabled", havingValue = "true") public class RentalSocket extends TextWebSocketHandler { + private static final org.slf4j.Logger LOG = org.slf4j.LoggerFactory.getLogger(RentalSocket.class); private static final String PATH = "/node/v1/socket"; private final RentalStore store; private final RentalIdentity identity; @@ -353,6 +354,10 @@ public class RentalSocket extends TextWebSocketHandler { time(task.get("signed_at")).toEpochMilli(), "nonce", text(task, "nonce"))); + LOG.info("租赁任务已推送 taskId={} taskNo={} orderId={} nodeId={} deliveryCount={} taskAgeMs={}", + task.get("id"), text(task, "task_no"), task.get("order_id"), + c.node, number(task, "delivery_count") + 1, + System.currentTimeMillis() - time(task.get("created_at")).toEpochMilli()); store.execute( "UPDATE rent_task SET" + " delivery_count=delivery_count+1,last_sent_at=?,delivery_session_epoch=?,version=version+1,updated_at=?" @@ -363,6 +368,8 @@ public class RentalSocket extends TextWebSocketHandler { task.get("id")); } } catch (Exception ex) { + LOG.warn("租赁任务推送或连接检查失败 nodeId={} diagnostic={}", + c.node, RentalDiagnostics.describe(ex)); try { c.socket.close(CloseStatus.SERVER_ERROR); } catch (Exception ignored) { diff --git a/ruoyi-system/src/main/java/com/ruoyi/system/rental/RentalTasks.java b/ruoyi-system/src/main/java/com/ruoyi/system/rental/RentalTasks.java index b83e56e..bc32394 100644 --- a/ruoyi-system/src/main/java/com/ruoyi/system/rental/RentalTasks.java +++ b/ruoyi-system/src/main/java/com/ruoyi/system/rental/RentalTasks.java @@ -213,6 +213,9 @@ public class RentalTasks { return true; }); if (Boolean.TRUE.equals(assigned)) { + log.info("租赁订单已分配 orderId={} nodeId={} orderAgeMs={}", orderId, + candidate.get("node_id"), System.currentTimeMillis() + - time(initial.get("created_at")).toEpochMilli()); return; } } diff --git a/ruoyi-system/src/main/java/com/ruoyi/system/rental/RentalWorkers.java b/ruoyi-system/src/main/java/com/ruoyi/system/rental/RentalWorkers.java index 56ae3a8..1a7b85a 100644 --- a/ruoyi-system/src/main/java/com/ruoyi/system/rental/RentalWorkers.java +++ b/ruoyi-system/src/main/java/com/ruoyi/system/rental/RentalWorkers.java @@ -27,6 +27,22 @@ public class RentalWorkers { private long monitoringCursor; private long dispatchCursor; + @org.springframework.beans.factory.annotation.Value("${rental.delivery.dispatch-interval-ms:3000}") + private long dispatchIntervalMs = 3000; + @org.springframework.beans.factory.annotation.Value("${rental.delivery.push-interval-ms:2000}") + private long pushIntervalMs = 2000; + + /** 启动即校验,避免配置为零造成热循环或过大造成难以定位的交付延迟。 */ + @javax.annotation.PostConstruct + public void validateDeliveryIntervals() { + require(dispatchIntervalMs >= 500 && dispatchIntervalMs <= 60000, + "订单调度间隔必须为500到60000毫秒"); + require(pushIntervalMs >= 500 && pushIntervalMs <= 60000, + "任务推送间隔必须为500到60000毫秒"); + LOG.info("租赁交付调度配置 dispatchIntervalMs={} pushIntervalMs={}", + dispatchIntervalMs, pushIntervalMs); + } + @org.springframework.beans.factory.annotation.Autowired private RentalReconciliation reconciliation; @@ -58,7 +74,6 @@ public class RentalWorkers { @Scheduled(fixedDelay = 15000) public void heartbeat() { - socket.tick(); store.execute( "UPDATE rent_node SET connection_status='OFFLINE',version=version+1,updated_at=?" + " WHERE connection_status<>'OFFLINE' AND heartbeat_expires_at> waiting = diff --git a/ruoyi-system/src/test/java/com/ruoyi/system/rental/RentalBusinessTest.java b/ruoyi-system/src/test/java/com/ruoyi/system/rental/RentalBusinessTest.java index e95219b..7e6871c 100644 --- a/ruoyi-system/src/test/java/com/ruoyi/system/rental/RentalBusinessTest.java +++ b/ruoyi-system/src/test/java/com/ruoyi/system/rental/RentalBusinessTest.java @@ -1291,6 +1291,29 @@ public class RentalBusinessTest { map("events", Collections.emptyList())); socket.handleTextMessage(first, envelope(credential, sync)); assertEquals("ONLINE", text(store.get("node", node, false), "connection_status")); + // 独立推送周期无需等待heartbeat;连续短周期调用不能提前重投同一任务。 + long deliveryOrder = number(create("DELIVERY-CADENCE"), "id"); + tasks.dispatch(deliveryOrder); + RentalWorkers workers = new RentalWorkers(store, tasks, socket, identity); + workers.validateDeliveryIntervals(); + workers.pushTasks(); + Map delivered = store.one("SELECT * FROM rent_task WHERE order_id=?", deliveryOrder); + assertNotNull(delivered); + assertEquals(1, number(delivered, "delivery_count")); + boolean taskFrameFound = false; + for (String message : first.messages) { + Map envelope = json.readValue(message, Map.class); + if (!envelope.containsKey("body")) { + continue; // 首个CHALLENGE不是签名业务帧。 + } + Map frame = json.readValue(text(envelope, "body"), Map.class); + if ("TASK_PUSH".equals(text(frame, "type"))) { + taskFrameFound = true; + } + } + assertTrue(taskFrameFound); + workers.pushTasks(); + assertEquals(1, number(store.get("task", number(delivered, "id"), false), "delivery_count")); StubSocket second = new StubSocket(); authenticate(socket, second); socket.afterConnectionClosed(first, org.springframework.web.socket.CloseStatus.NORMAL);