mirror of
https://github.com/lordmathis/llamactl.git
synced 2025-11-06 00:54:23 +00:00
Refactor health service to use centralized api client
This commit is contained in:
@@ -134,4 +134,7 @@ export const instancesApi = {
|
||||
const params = lines ? `?lines=${lines}` : "";
|
||||
return apiCall<string>(`/instances/${name}/logs${params}`, {}, "text");
|
||||
},
|
||||
|
||||
// GET /instances/{name}/proxy/health
|
||||
getHealth: (name: string) => apiCall<any>(`/instances/${name}/proxy/health`),
|
||||
};
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import { type HealthStatus } from '@/types/instance'
|
||||
import { instancesApi } from '@/lib/api'
|
||||
|
||||
type HealthCallback = (health: HealthStatus) => void
|
||||
|
||||
@@ -8,31 +9,33 @@ class HealthService {
|
||||
|
||||
async checkHealth(instanceName: string): Promise<HealthStatus> {
|
||||
try {
|
||||
const response = await fetch(`/api/v1/instances/${instanceName}/proxy/health`)
|
||||
await instancesApi.getHealth(instanceName)
|
||||
|
||||
if (response.status === 200) {
|
||||
return {
|
||||
status: 'ok',
|
||||
lastChecked: new Date()
|
||||
}
|
||||
} else if (response.status === 503) {
|
||||
const data = await response.json()
|
||||
} catch (error) {
|
||||
if (error instanceof Error) {
|
||||
// Check if it's a 503 (service unavailable - loading)
|
||||
if (error.message.includes('503')) {
|
||||
return {
|
||||
status: 'loading',
|
||||
message: data.error.message,
|
||||
lastChecked: new Date()
|
||||
}
|
||||
} else {
|
||||
return {
|
||||
status: 'error',
|
||||
message: `HTTP ${response.status}`,
|
||||
message: 'Instance is starting up',
|
||||
lastChecked: new Date()
|
||||
}
|
||||
}
|
||||
} catch (error) {
|
||||
|
||||
return {
|
||||
status: 'error',
|
||||
message: 'Network error',
|
||||
message: error.message,
|
||||
lastChecked: new Date()
|
||||
}
|
||||
}
|
||||
|
||||
return {
|
||||
status: 'error',
|
||||
message: 'Unknown error',
|
||||
lastChecked: new Date()
|
||||
}
|
||||
}
|
||||
@@ -82,7 +85,7 @@ class HealthService {
|
||||
}, 60000)
|
||||
|
||||
this.intervals.set(instanceName, interval)
|
||||
}, 2000)
|
||||
}, 5000)
|
||||
}
|
||||
|
||||
private stopHealthCheck(instanceName: string): void {
|
||||
|
||||
Reference in New Issue
Block a user