()
| 646 | } |
| 647 | |
| 648 | async function showStatus(): Promise<void> { |
| 649 | console.log("\n=== Batch Processor Status ===\n"); |
| 650 | |
| 651 | // Job queue stats |
| 652 | const jobStats = await db |
| 653 | .select({ |
| 654 | status: pipelineJobs.status, |
| 655 | count: sql<number>`COUNT(*)::int`, |
| 656 | }) |
| 657 | .from(pipelineJobs) |
| 658 | .where(eq(pipelineJobs.jobType, "ai_analysis")) |
| 659 | .groupBy(pipelineJobs.status); |
| 660 | |
| 661 | console.log("Pipeline Jobs:"); |
| 662 | for (const stat of jobStats) { |
| 663 | console.log(` ${stat.status}: ${stat.count}`); |
| 664 | } |
| 665 | if (jobStats.length === 0) console.log(" (none)"); |
| 666 | |
| 667 | // Document analysis stats |
| 668 | const docStats = await db |
| 669 | .select({ |
| 670 | status: documents.aiAnalysisStatus, |
| 671 | count: sql<number>`COUNT(*)::int`, |
| 672 | }) |
| 673 | .from(documents) |
| 674 | .groupBy(documents.aiAnalysisStatus); |
| 675 | |
| 676 | console.log("\nDocument Analysis Status:"); |
| 677 | for (const stat of docStats) { |
| 678 | console.log(` ${stat.status ?? "null"}: ${stat.count}`); |
| 679 | } |
| 680 | |
| 681 | // Budget |
| 682 | const { totalCents, docCount } = await getMonthlySpend(); |
| 683 | console.log(`\nMonthly Spend: ${formatCents(totalCents)} across ${docCount} documents`); |
| 684 | |
| 685 | // Top priority pending |
| 686 | const topJobs = await db |
| 687 | .select({ |
| 688 | priority: pipelineJobs.priority, |
| 689 | count: sql<number>`COUNT(*)::int`, |
| 690 | }) |
| 691 | .from(pipelineJobs) |
| 692 | .where( |
| 693 | and( |
| 694 | eq(pipelineJobs.jobType, "ai_analysis"), |
| 695 | eq(pipelineJobs.status, "pending"), |
| 696 | ) |
| 697 | ) |
| 698 | .groupBy(pipelineJobs.priority) |
| 699 | .orderBy(desc(pipelineJobs.priority)) |
| 700 | .limit(5); |
| 701 | |
| 702 | if (topJobs.length > 0) { |
| 703 | console.log("\nPending by Priority:"); |
| 704 | for (const j of topJobs) { |
| 705 | const dsName = Object.entries(DATASET_PRIORITY).find(([_, v]) => v === j.priority)?.[0]; |
no test coverage detected