feat: Implement Cronitor health monitor

This commit is contained in:
gpt-engineer-app[bot]
2025-11-05 15:38:11 +00:00
parent c1ef28e2f6
commit 35fdd16c6c
4 changed files with 173 additions and 5 deletions

View File

@@ -0,0 +1,37 @@
import { useQuery } from '@tanstack/react-query';
const CRONITOR_API_URL = 'https://cronitor.io/api/monitors/88kG4W?env=production&format=json';
const POLL_INTERVAL = 60000; // 60 seconds
interface CronitorResponse {
passing: boolean;
[key: string]: any; // Other fields we don't need
}
/**
* Hook to poll Cronitor API for health status
* Returns the monitor's passing status (true = healthy, false = down)
*/
export function useCronitorHealth() {
return useQuery({
queryKey: ['cronitor-health'],
queryFn: async (): Promise<CronitorResponse> => {
const response = await fetch(CRONITOR_API_URL, {
method: 'GET',
headers: {
'Accept': 'application/json',
},
});
if (!response.ok) {
throw new Error(`Cronitor API error: ${response.status}`);
}
return response.json();
},
refetchInterval: POLL_INTERVAL, // Auto-poll every 60 seconds
retry: 2, // Retry failed requests twice
staleTime: 30000, // Consider data stale after 30 seconds
gcTime: 5 * 60 * 1000, // Keep in cache for 5 minutes
});
}