monitor-generation.js 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. const { PrismaClient } = require('@prisma/client');
  2. const prisma = new PrismaClient();
  3. async function monitorGeneration() {
  4. const bookId = 1;
  5. console.log('开始监控书籍生成进度...\n');
  6. for (let i = 0; i < 10; i++) {
  7. const book = await prisma.book.findUnique({
  8. where: { id: bookId },
  9. select: {
  10. id: true,
  11. title: true,
  12. status: true,
  13. progress: true,
  14. errorMsg: true,
  15. }
  16. });
  17. const chapterCount = await prisma.bookChapter.count({
  18. where: { bookId, level: 1 }
  19. });
  20. const sectionCount = await prisma.bookChapter.count({
  21. where: { bookId, level: 2 }
  22. });
  23. const subsectionCount = await prisma.bookChapter.count({
  24. where: { bookId, level: 3 }
  25. });
  26. const completedContent = await prisma.bookChapter.count({
  27. where: { bookId, level: 3, contentStatus: 'completed' }
  28. });
  29. console.log(`[${new Date().toLocaleTimeString()}]`);
  30. console.log(` 状态: ${book.status}`);
  31. console.log(` 进度: ${book.progress}%`);
  32. console.log(` 章: ${chapterCount}, 节: ${sectionCount}, 小节: ${subsectionCount}`);
  33. console.log(` 已完成内容: ${completedContent}`);
  34. if (book.errorMsg) {
  35. console.log(` 错误: ${book.errorMsg}`);
  36. }
  37. console.log('');
  38. if (book.status === 'completed' || book.status === 'failed') {
  39. console.log('生成已结束!');
  40. break;
  41. }
  42. // 等待30秒
  43. await new Promise(resolve => setTimeout(resolve, 30000));
  44. }
  45. await prisma.$disconnect();
  46. }
  47. monitorGeneration().catch(console.error);