65 lines
1.4 KiB
JavaScript

import prisma from "~/server/utils/prisma";
export default defineEventHandler(async (event) => {
try {
// Get current user from auth middleware
const user = event.context.user;
if (!user) {
throw createError({
statusCode: 401,
statusMessage: "Authentication required",
});
}
// Get queue statistics from database
const [pending, processing, completed, failed] = await Promise.all([
// Get pending jobs count
prisma.notification_queue.count({
where: {
status: 'queued'
}
}),
// Get processing jobs count
prisma.notification_queue.count({
where: {
status: 'processing'
}
}),
// Get completed jobs count
prisma.notification_queue.count({
where: {
status: 'sent'
}
}),
// Get failed jobs count
prisma.notification_queue.count({
where: {
status: 'failed'
}
})
]);
return {
success: true,
data: {
pending,
processing,
completed,
failed
}
};
} catch (error) {
console.error('Error fetching queue statistics:', error);
if (error.statusCode) {
throw error;
}
throw createError({
statusCode: 500,
statusMessage: 'Failed to fetch queue statistics'
});
} finally {
await prisma.$disconnect();
}
});