mirror of
https://github.com/pacnpal/thrilltrack-explorer.git
synced 2025-12-23 20:11:12 -05:00
feat: Implement Cronitor health monitor
This commit is contained in:
37
src/hooks/useCronitorHealth.ts
Normal file
37
src/hooks/useCronitorHealth.ts
Normal 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
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user