From baffaefc679092f30bcbe51bb8b88070aa9ee6dd Mon Sep 17 00:00:00 2001 From: luqingjie <544309509@qq.com> Date: Sat, 31 Oct 2026 06:20:25 -0400 Subject: [PATCH] =?UTF-8?q?=E6=9C=AC=E5=9C=B0=E5=B9=BF=E6=92=AD=E5=92=8C?= =?UTF-8?q?=E5=87=BA=E7=A7=9F=E8=A1=A8=E7=A4=BA=E9=83=BD=E5=BC=80=E5=90=AF?= =?UTF-8?q?=E4=BA=86=EF=BC=8C=E5=B8=AE=E6=88=91=E6=B7=BB=E5=8A=A0=E6=97=A5?= =?UTF-8?q?=E5=BF=97=EF=BC=8C=E6=96=B9=E4=BE=BF=E6=8E=92=E6=9F=A5=E9=97=AE?= =?UTF-8?q?=E9=A2=98=EF=BC=8C=E5=8F=A6=E5=A4=96=E7=94=A8=E6=88=B7=E4=B8=8B?= =?UTF-8?q?=E7=A7=9F=E8=B5=81=E8=AE=A2=E5=8D=95=EF=BC=8C=E5=88=B0=E8=8A=82?= =?UTF-8?q?=E7=82=B9=E6=8E=A5=E6=94=B6=E8=AE=A2=E5=8D=95=E6=B6=88=E6=81=AF?= =?UTF-8?q?=E9=97=B4=E9=9A=94=E6=97=B6=E9=97=B4=E5=A4=AA=E4=B9=85=E4=BA=86?= =?UTF-8?q?=EF=BC=8C=E5=B8=AE=E6=88=91=E7=BC=A9=E7=9F=AD=EF=BC=8C=E6=8F=90?= =?UTF-8?q?=E4=BE=9B=E9=85=8D=E7=BD=AE=E9=A1=B9=EF=BC=8C=E9=BB=98=E8=AE=A4?= =?UTF-8?q?10=E5=B7=A6=E5=8F=B3=E8=A6=81=E8=83=BD=E6=94=B6=E5=88=B0?= =?UTF-8?q?=E8=AE=A2=E5=8D=95=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 6 +++++ .../src/main/resources/application-rental.yml | 5 ++++ .../com/ruoyi/system/rental/RentalSocket.java | 7 ++++++ .../com/ruoyi/system/rental/RentalTasks.java | 3 +++ .../ruoyi/system/rental/RentalWorkers.java | 25 +++++++++++++++++-- .../system/rental/RentalBusinessTest.java | 23 +++++++++++++++++ 6 files changed, 67 insertions(+), 2 deletions(-) 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);