#!/usr/bin/env ts-node /** * Script to check currently processing documents and their status */ import { getSupabaseServiceClient } from '../config/supabase'; import '../config/firebase'; async function checkCurrentProcessing() { console.log('\nšŸ” Checking Currently Processing Documents...\n'); try { const supabase = getSupabaseServiceClient(); // Check documents in various processing statuses const processingStatuses = ['processing', 'uploading', 'processing_llm', 'extracting_text']; for (const status of processingStatuses) { const { data, error } = await supabase .from('documents') .select('*') .eq('status', status) .order('updated_at', { ascending: false }) .limit(10); if (error) { console.error(`Error querying ${status}:`, error); continue; } if (data && data.length > 0) { console.log(`\nšŸ“„ Documents with status "${status}": ${data.length}`); console.log('─'.repeat(80)); const now = Date.now(); for (const doc of data) { const updatedAt = doc.updated_at ? new Date(doc.updated_at).getTime() : 0; const ageMinutes = Math.round((now - updatedAt) / 1000 / 60); console.log(`\n ID: ${doc.id}`); console.log(` File: ${doc.original_file_name}`); console.log(` Status: ${doc.status}`); console.log(` Updated: ${doc.updated_at} (${ageMinutes} minutes ago)`); console.log(` Created: ${doc.created_at}`); if (doc.error_message) { console.log(` Error: ${doc.error_message}`); } if (doc.file_path) { console.log(` File Path: ${doc.file_path}`); } // Check if stuck if (ageMinutes > 10) { console.log(` āš ļø STUCK: Not updated in ${ageMinutes} minutes`); } } } } // Also check most recent documents regardless of status console.log('\n\nšŸ“‹ Most Recent Documents (Last 10):'); console.log('─'.repeat(80)); const { data: recentDocs, error: recentError } = await supabase .from('documents') .select('*') .order('updated_at', { ascending: false }) .limit(10); if (recentError) { console.error('Error querying recent documents:', recentError); } else if (recentDocs) { const now = Date.now(); for (const doc of recentDocs) { const updatedAt = doc.updated_at ? new Date(doc.updated_at).getTime() : 0; const ageMinutes = Math.round((now - updatedAt) / 1000 / 60); console.log(`\n ${doc.id.substring(0, 8)}... - ${doc.status.padEnd(15)} - ${ageMinutes.toString().padStart(4)} min ago - ${doc.original_file_name}`); if (doc.error_message) { console.log(` Error: ${doc.error_message.substring(0, 100)}`); } } } console.log('\n'); } catch (error) { console.error('āŒ Error:', error); throw error; } } // Run if executed directly if (require.main === module) { checkCurrentProcessing() .then(() => process.exit(0)) .catch((error) => { console.error('Fatal error:', error); process.exit(1); }); } export { checkCurrentProcessing };