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