fix: 倒计时卡住根因修复 — Redis TTL缓冲+前端watchdog兜底

根因:CountdownService用while(sleep(1))阻塞循环推送倒计时,
Redis key TTL=wait_time,3台同时运行时worker争用导致循环慢于
Redis过期时间,key先过期→循环中断→倒计时冻结在当前秒数。

修复:
1. Redis TTL加10秒缓冲(waitTime+10),防止key提前过期
2. 前端加watchdog兜底:服务端2秒没推送就本地继续倒计时
This commit is contained in:
testadmin
2026-05-19 14:25:48 +08:00
parent aa74a6edc1
commit 8edc071997
9 changed files with 97 additions and 1 deletions
+1 -1
View File
@@ -27,7 +27,7 @@ class CountdownService
//处理倒计时
$waitTime = intval($tableInfo['wait_time']);
//将倒计时用作是redis的过期时间
RedisUtil::save('countdown_'.$numberTabInfo['id'],$waitTime,$waitTime);
RedisUtil::save('countdown_'.$numberTabInfo['id'],$waitTime,$waitTime + 10);
while($waitTime >= 0){
$countdown = Cache::store('redis')->get('countdown_'.$numberTabInfo['id']);
if ($countdown){
+12
View File
@@ -532,9 +532,21 @@ websocket.on('resetBoot',function(data){
}
}
});
var _cdTimer = null;
var _cdVal = 0;
websocket.on('startBetCountDown',function(data){
if(data.status == true && data.table_id == table_id){
_cdVal = data.count_down;
countDown(data.count_down);
if(_cdTimer) clearTimeout(_cdTimer);
if(_cdVal > 0){
_cdTimer = setTimeout(function _tick(){
_cdVal--;
if(_cdVal >= 0) countDown(_cdVal);
if(_cdVal > 0) _cdTimer = setTimeout(_tick, 1000);
else _cdTimer = null;
}, 2000);
}
}
});
websocket.on('endBet',function(data){
+12
View File
@@ -259,9 +259,21 @@ websocket.on('resetBoot',function(data){
layer.msg(lang[data.msg]);
}
});
var _cdTimer = null;
var _cdVal = 0;
websocket.on('startBetCountDown',function(data){
if(data.status == true && data.table_id == table_id){
_cdVal = data.count_down;
countDown(data.count_down);
if(_cdTimer) clearTimeout(_cdTimer);
if(_cdVal > 0){
_cdTimer = setTimeout(function _tick(){
_cdVal--;
if(_cdVal >= 0) countDown(_cdVal);
if(_cdVal > 0) _cdTimer = setTimeout(_tick, 1000);
else _cdTimer = null;
}, 2000);
}
}
});
websocket.on('endBet',function(data){
+12
View File
@@ -504,9 +504,21 @@ websocket.on('resetBoot',function(data){
}
}
});
var _cdTimer = null;
var _cdVal = 0;
websocket.on('startBetCountDown',function(data){
if(data.status == true && data.table_id == table_id){
_cdVal = data.count_down;
countDown(data.count_down);
if(_cdTimer) clearTimeout(_cdTimer);
if(_cdVal > 0){
_cdTimer = setTimeout(function _tick(){
_cdVal--;
if(_cdVal >= 0) countDown(_cdVal);
if(_cdVal > 0) _cdTimer = setTimeout(_tick, 1000);
else _cdTimer = null;
}, 2000);
}
}
});
websocket.on('endBet',function(data){
@@ -520,9 +520,21 @@ websocket.on('resetBoot',function(data){
}
}
});
var _cdTimer = null;
var _cdVal = 0;
websocket.on('startBetCountDown',function(data){
if(data.status == true && data.table_id == table_id){
_cdVal = data.count_down;
countDown(data.count_down);
if(_cdTimer) clearTimeout(_cdTimer);
if(_cdVal > 0){
_cdTimer = setTimeout(function _tick(){
_cdVal--;
if(_cdVal >= 0) countDown(_cdVal);
if(_cdVal > 0) _cdTimer = setTimeout(_tick, 1000);
else _cdTimer = null;
}, 2000);
}
}
});
websocket.on('endBet',function(data){
+12
View File
@@ -197,9 +197,21 @@ websocket.on('resetBoot',function(data){
}
}
});
var _cdTimer = null;
var _cdVal = 0;
websocket.on('startBetCountDown',function(data){
if(data.status == true && data.table_id == table_id){
_cdVal = data.count_down;
countDown(data.count_down);
if(_cdTimer) clearTimeout(_cdTimer);
if(_cdVal > 0){
_cdTimer = setTimeout(function _tick(){
_cdVal--;
if(_cdVal >= 0) countDown(_cdVal);
if(_cdVal > 0) _cdTimer = setTimeout(_tick, 1000);
else _cdTimer = null;
}, 2000);
}
}
});
websocket.on('endBet',function(data){
+12
View File
@@ -495,9 +495,21 @@ websocket.on('resetBoot',function(data){
}
}
});
var _cdTimer = null;
var _cdVal = 0;
websocket.on('startBetCountDown',function(data){
if(data.status == true && data.table_id == table_id){
_cdVal = data.count_down;
countDown(data.count_down);
if(_cdTimer) clearTimeout(_cdTimer);
if(_cdVal > 0){
_cdTimer = setTimeout(function _tick(){
_cdVal--;
if(_cdVal >= 0) countDown(_cdVal);
if(_cdVal > 0) _cdTimer = setTimeout(_tick, 1000);
else _cdTimer = null;
}, 2000);
}
}
});
websocket.on('endBet',function(data){
+12
View File
@@ -565,9 +565,21 @@ websocket.on('resetBoot',function(data){
}
}
});
var _cdTimer = null;
var _cdVal = 0;
websocket.on('startBetCountDown',function(data){
if(data.status == true && data.table_id == table_id){
_cdVal = data.count_down;
countDown(data.count_down);
if(_cdTimer) clearTimeout(_cdTimer);
if(_cdVal > 0){
_cdTimer = setTimeout(function _tick(){
_cdVal--;
if(_cdVal >= 0) countDown(_cdVal);
if(_cdVal > 0) _cdTimer = setTimeout(_tick, 1000);
else _cdTimer = null;
}, 2000);
}
}
});
websocket.on('endBet',function(data){
@@ -177,9 +177,21 @@ websocket.on('resetBoot',function(data){
}
}
});
var _cdTimer = null;
var _cdVal = 0;
websocket.on('startBetCountDown',function(data){
if(data.status == true && data.table_id == table_id){
_cdVal = data.count_down;
countDown(data.count_down);
if(_cdTimer) clearTimeout(_cdTimer);
if(_cdVal > 0){
_cdTimer = setTimeout(function _tick(){
_cdVal--;
if(_cdVal >= 0) countDown(_cdVal);
if(_cdVal > 0) _cdTimer = setTimeout(_tick, 1000);
else _cdTimer = null;
}, 2000);
}
}
});
websocket.on('endBet',function(data){