Files

52 lines
1.1 KiB
JavaScript

import prisma from "~/server/utils/prisma";
export default defineEventHandler(async (event) => {
try {
// Get current date and set to start of day
const today = new Date();
today.setHours(0, 0, 0, 0);
// Count pending jobs
const pending = await prisma.notification_queue.count({
where: {
status: "queued",
},
});
// Count completed jobs today
const completed = await prisma.notification_queue.count({
where: {
status: "completed",
updated_at: {
gte: today,
},
},
});
// Count failed jobs
const failed = await prisma.notification_queue.count({
where: {
status: "failed",
},
});
return {
success: true,
data: {
pending,
completed,
failed,
},
};
} catch (error) {
console.error("Error fetching queue stats:", error);
throw createError({
statusCode: 500,
statusMessage: "Failed to fetch queue statistics",
data: {
error: error.message,
},
});
} finally {
}
});