Files
cim_summary/backend/check-document-status.js
Jon 185c780486
Some checks failed
CI/CD Pipeline / Backend - Lint & Test (push) Has been cancelled
CI/CD Pipeline / Frontend - Lint & Test (push) Has been cancelled
CI/CD Pipeline / Security Scan (push) Has been cancelled
CI/CD Pipeline / Build Backend (push) Has been cancelled
CI/CD Pipeline / Build Frontend (push) Has been cancelled
CI/CD Pipeline / Integration Tests (push) Has been cancelled
CI/CD Pipeline / Deploy to Staging (push) Has been cancelled
CI/CD Pipeline / Deploy to Production (push) Has been cancelled
CI/CD Pipeline / Performance Tests (push) Has been cancelled
CI/CD Pipeline / Dependency Updates (push) Has been cancelled
🚀 Update to Claude 3.7 latest and fix LLM processing issues
- Updated Anthropic API to latest version (2024-01-01)
- Set Claude 3.7 Sonnet Latest as primary model
- Removed deprecated Opus 3.5 references
- Fixed LLM response validation and JSON parsing
- Improved error handling and logging
- Updated model configurations and pricing
- Enhanced document processing reliability
- Fixed TypeScript type issues
- Updated environment configuration
2025-08-17 17:31:56 -04:00

126 lines
4.2 KiB
JavaScript

const { Pool } = require('pg');
// Database configuration
const pool = new Pool({
connectionString: process.env.SUPABASE_URL ?
process.env.SUPABASE_URL.replace('postgresql://', 'postgresql://postgres.ghurdhqdcrxeugyuxxqa:') :
'postgresql://postgres.ghurdhqdcrxeugyuxxqa:Ze7KGPXLa6CGDN0gsYfgBEP2N4Y-8YGUB_H6xyxggu8@aws-0-us-east-1.pooler.supabase.com:6543/postgres',
ssl: {
rejectUnauthorized: false
}
});
async function checkDocumentStatus(documentId) {
try {
console.log(`🔍 Checking status for document: ${documentId}`);
// Check document status
const documentQuery = `
SELECT
id,
original_file_name,
status,
error_message,
analysis_data,
created_at,
processing_completed_at,
file_path
FROM documents
WHERE id = $1
`;
const documentResult = await pool.query(documentQuery, [documentId]);
if (documentResult.rows.length === 0) {
console.log('❌ Document not found');
return;
}
const document = documentResult.rows[0];
console.log('\n📄 Document Information:');
console.log(` ID: ${document.id}`);
console.log(` Name: ${document.original_file_name}`);
console.log(` Status: ${document.status}`);
console.log(` Created: ${document.created_at}`);
console.log(` Completed: ${document.processing_completed_at || 'Not completed'}`);
console.log(` File Path: ${document.file_path}`);
console.log(` Error: ${document.error_message || 'None'}`);
console.log(` Has Analysis Data: ${document.analysis_data ? 'Yes' : 'No'}`);
if (document.analysis_data) {
console.log('\n📊 Analysis Data Keys:');
console.log(` ${Object.keys(document.analysis_data).join(', ')}`);
}
// Check processing jobs
const jobsQuery = `
SELECT
id,
type,
status,
progress,
error_message,
created_at,
started_at,
completed_at
FROM processing_jobs
WHERE document_id = $1
ORDER BY created_at DESC
`;
const jobsResult = await pool.query(jobsQuery, [documentId]);
console.log('\n🔧 Processing Jobs:');
if (jobsResult.rows.length === 0) {
console.log(' No processing jobs found');
} else {
jobsResult.rows.forEach((job, index) => {
console.log(` Job ${index + 1}:`);
console.log(` ID: ${job.id}`);
console.log(` Type: ${job.type}`);
console.log(` Status: ${job.status}`);
console.log(` Progress: ${job.progress}%`);
console.log(` Created: ${job.created_at}`);
console.log(` Started: ${job.started_at || 'Not started'}`);
console.log(` Completed: ${job.completed_at || 'Not completed'}`);
console.log(` Error: ${job.error_message || 'None'}`);
});
}
// Check if document is stuck in processing
if (document.status === 'processing_llm' || document.status === 'processing') {
const processingTime = new Date() - new Date(document.created_at);
const hoursSinceCreation = processingTime / (1000 * 60 * 60);
console.log(`\n⚠️ Document Processing Analysis:`);
console.log(` Time since creation: ${hoursSinceCreation.toFixed(2)} hours`);
if (hoursSinceCreation > 1) {
console.log(` ⚠️ Document has been processing for over 1 hour - may be stuck`);
// Check if we should reset the status
if (hoursSinceCreation > 2) {
console.log(` 🔄 Document has been processing for over 2 hours - suggesting reset`);
console.log(` 💡 Consider resetting status to 'uploaded' to allow reprocessing`);
}
}
}
} catch (error) {
console.error('❌ Error checking document status:', error);
} finally {
await pool.end();
}
}
// Get document ID from command line argument
const documentId = process.argv[2];
if (!documentId) {
console.log('Usage: node check-document-status.js <document-id>');
console.log('Example: node check-document-status.js f5509048-d282-4316-9b65-cb89bf8ac09d');
process.exit(1);
}
checkDocumentStatus(documentId);