Skip to content

Commit 50c3601

Browse files
Update update.sh
1 parent c3a327b commit 50c3601

File tree

2 files changed

+18
-6
lines changed

2 files changed

+18
-6
lines changed

src/app/_components/VersionDisplay.tsx

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ export function VersionDisplay() {
7777
const [isNetworkError, setIsNetworkError] = useState(false);
7878
const [updateLogs, setUpdateLogs] = useState<string[]>([]);
7979
const [shouldSubscribe, setShouldSubscribe] = useState(false);
80+
const [updateStartTime, setUpdateStartTime] = useState<number | null>(null);
8081
const lastLogTimeRef = useRef<number>(Date.now());
8182
const reconnectIntervalRef = useRef<NodeJS.Timeout | null>(null);
8283

@@ -99,7 +100,7 @@ export function VersionDisplay() {
99100
});
100101

101102
// Poll for update logs
102-
const { data: updateLogsData, refetch: refetchLogs } = api.version.getUpdateLogs.useQuery(undefined, {
103+
const { data: updateLogsData } = api.version.getUpdateLogs.useQuery(undefined, {
103104
enabled: shouldSubscribe,
104105
refetchInterval: 1000, // Poll every second
105106
refetchIntervalInBackground: true,
@@ -126,18 +127,22 @@ export function VersionDisplay() {
126127
const checkInterval = setInterval(() => {
127128
const timeSinceLastLog = Date.now() - lastLogTimeRef.current;
128129

129-
// If no logs for 3 seconds and we're updating, assume server is restarting
130-
if (timeSinceLastLog > 3000 && isUpdating) {
130+
// Only start reconnection if we've been updating for at least 30 seconds
131+
// and no logs for 10 seconds (to avoid premature reconnection during npm install)
132+
const hasBeenUpdatingLongEnough = updateStartTime && (Date.now() - updateStartTime) > 60000;
133+
const noLogsForAWhile = timeSinceLastLog > 40000;
134+
135+
if (hasBeenUpdatingLongEnough && noLogsForAWhile && isUpdating) {
131136
setIsNetworkError(true);
132137
setUpdateLogs(prev => [...prev, 'Server restarting... waiting for reconnection...']);
133138

134139
// Start trying to reconnect
135140
startReconnectAttempts();
136141
}
137-
}, 1000);
142+
}, 1500); // Check every 2 seconds instead of 1
138143

139144
return () => clearInterval(checkInterval);
140-
}, [shouldSubscribe, isUpdating]);
145+
}, [shouldSubscribe, isUpdating, updateStartTime]);
141146

142147
// Attempt to reconnect and reload page when server is back
143148
const startReconnectAttempts = () => {
@@ -184,6 +189,7 @@ export function VersionDisplay() {
184189
setIsNetworkError(false);
185190
setUpdateLogs([]);
186191
setShouldSubscribe(false);
192+
setUpdateStartTime(Date.now());
187193
lastLogTimeRef.current = Date.now();
188194
executeUpdate.mutate();
189195
};

src/server/api/routers/version.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,13 @@ export const versionRouter = createTRPCRouter({
151151
line.includes('Update complete') ||
152152
line.includes('Server restarting') ||
153153
line.includes('npm start') ||
154-
line.includes('Restarting server')
154+
line.includes('Restarting server') ||
155+
line.includes('Server started') ||
156+
line.includes('Ready on http') ||
157+
line.includes('Application started') ||
158+
line.includes('Service enabled and started successfully') ||
159+
line.includes('Service is running') ||
160+
line.includes('Update completed successfully')
155161
);
156162

157163
return {

0 commit comments

Comments
 (0)