103 lines
3.1 KiB
TypeScript
103 lines
3.1 KiB
TypeScript
import { PrismaClient } from '@prisma/client';
|
||
|
||
const prisma = new PrismaClient();
|
||
|
||
async function checkStuckTasks() {
|
||
try {
|
||
// 查找最近创建的任务
|
||
const recentTasks = await prisma.aIContentTask.findMany({
|
||
orderBy: { createdAt: 'desc' },
|
||
take: 5,
|
||
select: {
|
||
id: true,
|
||
status: true,
|
||
generationStyle: true,
|
||
createdAt: true,
|
||
courseId: true,
|
||
suggestedTitle: true,
|
||
sourceText: true,
|
||
outline: true,
|
||
},
|
||
});
|
||
|
||
console.log('\n=== 最近5个任务 ===');
|
||
recentTasks.forEach((task, index) => {
|
||
console.log(`\n任务 ${index + 1}:`);
|
||
console.log(` ID: ${task.id}`);
|
||
console.log(` 状态: ${task.status}`);
|
||
console.log(` 风格: ${task.generationStyle || '未选择'}`);
|
||
console.log(` 创建时间: ${task.createdAt}`);
|
||
console.log(` 课程ID: ${task.courseId || '无'}`);
|
||
console.log(` 标题: ${task.suggestedTitle || '未生成'}`);
|
||
console.log(` 文本长度: ${task.sourceText?.length || 0} 字符`);
|
||
console.log(` 是否有大纲: ${task.outline ? '是' : '否'}`);
|
||
});
|
||
|
||
// 查找卡住的任务(pending 或 analyzing 状态超过1分钟)
|
||
const oneMinuteAgo = new Date(Date.now() - 60 * 1000);
|
||
const stuckTasks = await prisma.aIContentTask.findMany({
|
||
where: {
|
||
status: {
|
||
in: ['pending', 'analyzing'],
|
||
},
|
||
createdAt: {
|
||
lt: oneMinuteAgo,
|
||
},
|
||
},
|
||
select: {
|
||
id: true,
|
||
status: true,
|
||
generationStyle: true,
|
||
createdAt: true,
|
||
courseId: true,
|
||
},
|
||
});
|
||
|
||
if (stuckTasks.length > 0) {
|
||
console.log('\n=== 卡住的任务(超过1分钟未更新)===');
|
||
stuckTasks.forEach((task) => {
|
||
console.log(`\n任务 ID: ${task.id}`);
|
||
console.log(` 状态: ${task.status}`);
|
||
console.log(` 风格: ${task.generationStyle || '未选择'}`);
|
||
console.log(` 创建时间: ${task.createdAt}`);
|
||
console.log(` 课程ID: ${task.courseId || '无'}`);
|
||
});
|
||
} else {
|
||
console.log('\n✅ 没有发现卡住的任务');
|
||
}
|
||
|
||
// 检查课程进度
|
||
if (recentTasks.length > 0) {
|
||
const courseIds = recentTasks
|
||
.map((t) => t.courseId)
|
||
.filter((id): id is string => id !== null);
|
||
|
||
if (courseIds.length > 0) {
|
||
const courses = await prisma.course.findMany({
|
||
where: { id: { in: courseIds } },
|
||
select: {
|
||
id: true,
|
||
title: true,
|
||
generationProgress: true,
|
||
generationStatus: true,
|
||
},
|
||
});
|
||
|
||
console.log('\n=== 关联的课程进度 ===');
|
||
courses.forEach((course) => {
|
||
console.log(`\n课程 ID: ${course.id}`);
|
||
console.log(` 标题: ${course.title}`);
|
||
console.log(` 生成状态: ${course.generationStatus || '无'}`);
|
||
console.log(` 生成进度: ${(course.generationProgress || 0) * 100}%`);
|
||
});
|
||
}
|
||
}
|
||
} catch (error: any) {
|
||
console.error('检查失败:', error.message);
|
||
} finally {
|
||
await prisma.$disconnect();
|
||
}
|
||
}
|
||
|
||
checkStuckTasks();
|