Files
filezzy-staging/backend/scripts/inspect-job.ts
2026-02-04 14:16:04 +01:00

71 lines
2.0 KiB
TypeScript
Raw Blame History

This file contains invisible Unicode characters
This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
/**
* Inspect a job: userId, status, outputFileId, and whether JOB_COMPLETED email was sent.
* Usage: npx ts-node scripts/inspect-job.ts <jobId>
* Example: npx ts-node scripts/inspect-job.ts aef1d6f7-ed2f-431b-88ac-b33b22775037
*
* Job-completed emails are only sent for jobs with a userId (logged-in user). Guest jobs have userId = null.
*/
import { PrismaClient } from '@prisma/client';
const prisma = new PrismaClient();
async function main() {
const jobId = process.argv[2];
if (!jobId) {
console.log('Usage: npx ts-node scripts/inspect-job.ts <jobId>');
process.exit(1);
}
const job = await prisma.job.findUnique({
where: { id: jobId },
select: {
id: true,
userId: true,
status: true,
outputFileId: true,
createdAt: true,
updatedAt: true,
tool: { select: { name: true, slug: true } },
user: { select: { email: true } },
},
});
if (!job) {
console.log('Job not found:', jobId);
await prisma.$disconnect();
process.exit(1);
}
const emailLog = await prisma.emailLog.findFirst({
where: {
emailType: 'JOB_COMPLETED',
metadata: { path: ['jobId'], equals: job.id },
},
select: { status: true, recipientEmail: true, sentAt: true, errorMessage: true },
});
console.log(JSON.stringify({
jobId: job.id,
status: job.status,
userId: job.userId,
userEmail: job.user?.email ?? null,
outputFileId: job.outputFileId,
tool: job.tool?.name ?? job.tool?.slug,
updatedAt: job.updatedAt,
emailEligible: !!(job.userId && job.outputFileId && job.status === 'COMPLETED'),
emailSent: emailLog ? { status: emailLog.status, to: emailLog.recipientEmail, sentAt: emailLog.sentAt, error: emailLog.errorMessage } : null,
}, null, 2));
if (job.status === 'COMPLETED' && !job.userId) {
console.log('\n⚠ This is a guest job (no userId). Job-completed emails are only sent for logged-in users.');
}
await prisma.$disconnect();
}
main().catch((e) => {
console.error(e);
process.exit(1);
});