本地广播和出租表示都开启了,帮我添加日志,方便排查问题,另外用户下租赁订单,到节点接收订单消息间隔时间太久了,帮我缩短,提供配置项,默认10左右要能收到订单。
This commit is contained in:
1 parent
849aff5ee1
commit
baffaefc67
6 files changed
+67
-2
No files matched your search
@@ -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) {
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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<?",
|
||||
@@ -68,7 +83,13 @@ public class RentalWorkers {
|
||||
store.execute("DELETE FROM rent_nonce WHERE expires_at<? LIMIT 1000", now());
|
||||
}
|
||||
|
||||
@Scheduled(fixedDelay = 5000)
|
||||
/** 推送独立于心跳清理,避免订单调度后再等待15秒。仍由数据库任务保证可靠重投。 */
|
||||
@Scheduled(fixedDelayString = "${rental.delivery.push-interval-ms:2000}")
|
||||
public void pushTasks() {
|
||||
socket.tick();
|
||||
}
|
||||
|
||||
@Scheduled(fixedDelayString = "${rental.delivery.dispatch-interval-ms:3000}")
|
||||
public void dispatch() {
|
||||
// 主键轮转,资源不足的早期订单不能永久阻塞其他网络或资源类型的订单。
|
||||
List<Map<String, Object>> waiting =
|
||||
|
||||
Reference in new issue
Block a user