mirror of
https://github.com/lordmathis/llamactl.git
synced 2025-12-24 10:04:26 +00:00
Improve health checks for instances
This commit is contained in:
@@ -7,24 +7,23 @@ export function useInstanceHealth(instanceName: string, instanceStatus: Instance
|
||||
const [health, setHealth] = useState<HealthStatus | undefined>()
|
||||
|
||||
useEffect(() => {
|
||||
if (instanceStatus === "stopped") {
|
||||
setHealth({ status: "unknown", lastChecked: new Date() })
|
||||
return
|
||||
}
|
||||
|
||||
if (instanceStatus === "failed") {
|
||||
setHealth({ status: instanceStatus, lastChecked: new Date() })
|
||||
return
|
||||
}
|
||||
|
||||
// Subscribe to health updates for this instance
|
||||
const unsubscribe = healthService.subscribe(instanceName, (healthStatus) => {
|
||||
setHealth(healthStatus)
|
||||
})
|
||||
|
||||
// Cleanup subscription on unmount or when instanceStatus changes
|
||||
// Cleanup subscription on unmount or when instance changes
|
||||
return unsubscribe
|
||||
}, [instanceName])
|
||||
|
||||
// Trigger health check when instance status changes to active states
|
||||
useEffect(() => {
|
||||
if (instanceStatus === 'running' || instanceStatus === 'restarting') {
|
||||
healthService.refreshHealth(instanceName).catch(error => {
|
||||
console.error(`Failed to refresh health for ${instanceName}:`, error)
|
||||
})
|
||||
}
|
||||
}, [instanceName, instanceStatus])
|
||||
|
||||
return health
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user