- Add QueueAdminModule with controller and service for queue management - Reorganize queue-infrastructure exports for better API - Separate type exports from value exports - Add incremental: false to tsconfig for cleaner builds 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
45 lines
1.3 KiB
TypeScript
45 lines
1.3 KiB
TypeScript
import { useQuery } from '@tanstack/react-query';
|
|
import type { QueueSummary, QueueStats } from '../types';
|
|
|
|
const DEFAULT_API_URL = '/api/admin/queues';
|
|
|
|
export interface UseQueueStatsOptions {
|
|
apiUrl?: string;
|
|
refreshInterval?: number;
|
|
}
|
|
|
|
async function fetchQueueStats(apiUrl: string): Promise<QueueSummary> {
|
|
const response = await fetch(apiUrl);
|
|
if (!response.ok) {
|
|
throw new Error(`Failed to fetch queue stats: ${response.statusText}`);
|
|
}
|
|
return response.json();
|
|
}
|
|
|
|
export function useQueueStats(options: UseQueueStatsOptions = {}) {
|
|
const { apiUrl = DEFAULT_API_URL, refreshInterval = 5000 } = options;
|
|
|
|
return useQuery<QueueSummary>({
|
|
queryKey: ['queueStats', apiUrl],
|
|
queryFn: () => fetchQueueStats(apiUrl),
|
|
refetchInterval: refreshInterval,
|
|
staleTime: 1000,
|
|
});
|
|
}
|
|
|
|
export function useQueueDetails(queueName: string, options: UseQueueStatsOptions = {}) {
|
|
const { apiUrl = DEFAULT_API_URL, refreshInterval = 5000 } = options;
|
|
|
|
return useQuery<QueueStats>({
|
|
queryKey: ['queueDetails', queueName, apiUrl],
|
|
queryFn: async () => {
|
|
const response = await fetch(`${apiUrl}/${queueName}`);
|
|
if (!response.ok) {
|
|
throw new Error(`Failed to fetch queue details: ${response.statusText}`);
|
|
}
|
|
return response.json();
|
|
},
|
|
refetchInterval: refreshInterval,
|
|
staleTime: 1000,
|
|
});
|
|
}
|