mirror of
https://github.com/lukaszraczylo/claude-mnemonic.git
synced 2026-06-11 00:09:28 +00:00
Fix autoupdate, add healtcheck status to the dashboard
This commit is contained in:
@@ -2,3 +2,4 @@ export { useSSE } from './useSSE'
|
||||
export { useStats } from './useStats'
|
||||
export { useTimeline } from './useTimeline'
|
||||
export { useUpdate } from './useUpdate'
|
||||
export { useHealth } from './useHealth'
|
||||
|
||||
@@ -0,0 +1,55 @@
|
||||
import { ref, onMounted, onUnmounted } from 'vue'
|
||||
import type { SelfCheckResponse } from '@/types'
|
||||
|
||||
const CHECK_INTERVAL = 30 * 1000 // 30 seconds
|
||||
|
||||
export function useHealth() {
|
||||
const health = ref<SelfCheckResponse | null>(null)
|
||||
const loading = ref(false)
|
||||
const error = ref<string | null>(null)
|
||||
let intervalId: ReturnType<typeof setInterval> | null = null
|
||||
|
||||
async function fetchHealth() {
|
||||
loading.value = true
|
||||
error.value = null
|
||||
try {
|
||||
const response = await fetch('/api/selfcheck')
|
||||
if (!response.ok) {
|
||||
throw new Error(`HTTP ${response.status}`)
|
||||
}
|
||||
health.value = await response.json()
|
||||
} catch (e) {
|
||||
error.value = e instanceof Error ? e.message : 'Unknown error'
|
||||
health.value = null
|
||||
} finally {
|
||||
loading.value = false
|
||||
}
|
||||
}
|
||||
|
||||
function startPolling() {
|
||||
fetchHealth()
|
||||
intervalId = setInterval(fetchHealth, CHECK_INTERVAL)
|
||||
}
|
||||
|
||||
function stopPolling() {
|
||||
if (intervalId) {
|
||||
clearInterval(intervalId)
|
||||
intervalId = null
|
||||
}
|
||||
}
|
||||
|
||||
onMounted(() => {
|
||||
startPolling()
|
||||
})
|
||||
|
||||
onUnmounted(() => {
|
||||
stopPolling()
|
||||
})
|
||||
|
||||
return {
|
||||
health,
|
||||
loading,
|
||||
error,
|
||||
refresh: fetchHealth
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user