fix: client-server time desync
This commit is contained in:
parent
7f6f79f028
commit
85b078fce3
|
|
@ -82,7 +82,13 @@ function watchAccount(onPing) {
|
|||
buf = lines.pop() ?? '';
|
||||
for (const line of lines) {
|
||||
if (line.startsWith('data: ')) {
|
||||
try { onPing(JSON.parse(line.slice(6))); } catch {}
|
||||
try {
|
||||
const ping = JSON.parse(line.slice(6));
|
||||
if (ping.checked_at && new Date(ping.checked_at).getTime() > Date.now()) {
|
||||
ping.checked_at = new Date().toISOString();
|
||||
}
|
||||
onPing(ping);
|
||||
} catch {}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
15
deploy.sh
15
deploy.sh
|
|
@ -102,6 +102,18 @@ if [ $# -eq 0 ]; then
|
|||
exit 1
|
||||
fi
|
||||
|
||||
sync_time() {
|
||||
echo "[sync] Syncing time on all servers..."
|
||||
ALL_HOSTS=("$DB_HOST" "$API_HOST" "$WEB_HOST" "${MONITOR_HOSTS[@]}")
|
||||
for host in "${ALL_HOSTS[@]}"; do
|
||||
(
|
||||
$SSH "$host" "chronyc makestep 2>/dev/null || ntpdate -s pool.ntp.org 2>/dev/null || timedatectl set-ntp true 2>/dev/null; echo \"$(hostname 2>/dev/null || echo $host): $(date -u +%H:%M:%S.%N)\""
|
||||
) &
|
||||
done
|
||||
wait
|
||||
echo "[sync] All servers synced"
|
||||
}
|
||||
|
||||
deploy_target() {
|
||||
case "$1" in
|
||||
db) deploy_db ;;
|
||||
|
|
@ -110,8 +122,9 @@ deploy_target() {
|
|||
web) deploy_web ;;
|
||||
monitor) deploy_monitor ;;
|
||||
nuke-db) nuke_db ;;
|
||||
sync) sync_time ;;
|
||||
all) deploy_db; deploy_api; deploy_pay; deploy_web; deploy_monitor ;;
|
||||
*) echo "Unknown target: $1 (valid: web, api, pay, monitor, db, nuke-db, all)"; exit 1 ;;
|
||||
*) echo "Unknown target: $1 (valid: web, api, pay, monitor, db, nuke-db, sync, all)"; exit 1 ;;
|
||||
esac
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue