Files
cim_summary/backend/reset-stuck-document.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

117 lines
3.9 KiB
JavaScript
Raw Blame History

This file contains invisible Unicode characters
This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
const { Pool } = require('pg');
// Database configuration - using the same connection as the main app
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 resetStuckDocument(documentId) {
try {
console.log(`🔄 Resetting stuck document: ${documentId}`);
// First, check the current status
const checkQuery = `
SELECT
id,
original_file_name,
status,
error_message,
created_at,
processing_completed_at
FROM documents
WHERE id = $1
`;
const checkResult = await pool.query(checkQuery, [documentId]);
if (checkResult.rows.length === 0) {
console.log('❌ Document not found');
return;
}
const document = checkResult.rows[0];
console.log('\n📄 Current Document Status:');
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(` Error: ${document.error_message || 'None'}`);
// Check if document is actually stuck
const processingTime = new Date() - new Date(document.created_at);
const hoursSinceCreation = processingTime / (1000 * 60 * 60);
console.log(`\n⏱️ Processing Time Analysis:`);
console.log(` Time since creation: ${hoursSinceCreation.toFixed(2)} hours`);
if (hoursSinceCreation < 0.5) {
console.log('⚠️ Document has been processing for less than 30 minutes - may not be stuck');
console.log('💡 Consider waiting a bit longer before resetting');
return;
}
// Reset the document status
const resetQuery = `
UPDATE documents
SET
status = 'uploaded',
error_message = NULL,
processing_completed_at = NULL,
analysis_data = NULL,
generated_summary = NULL,
updated_at = CURRENT_TIMESTAMP
WHERE id = $1
`;
const resetResult = await pool.query(resetQuery, [documentId]);
if (resetResult.rowCount > 0) {
console.log('\n✅ Document successfully reset!');
console.log(' Status changed to: uploaded');
console.log(' Error message cleared');
console.log(' Analysis data cleared');
console.log(' Ready for reprocessing');
// Also clear any stuck processing jobs
const clearJobsQuery = `
UPDATE processing_jobs
SET
status = 'failed',
error_message = 'Document reset by admin',
completed_at = CURRENT_TIMESTAMP
WHERE document_id = $1 AND status IN ('pending', 'processing')
`;
const clearJobsResult = await pool.query(clearJobsQuery, [documentId]);
console.log(` Cleared ${clearJobsResult.rowCount} stuck processing jobs`);
} else {
console.log('❌ Failed to reset document');
}
} catch (error) {
console.error('❌ Error resetting document:', error);
} finally {
await pool.end();
}
}
// Get document ID from command line argument
const documentId = process.argv[2];
if (!documentId) {
console.log('Usage: node reset-stuck-document.js <document-id>');
console.log('Example: node reset-stuck-document.js f5509048-d282-4316-9b65-cb89bf8ac09d');
console.log('\n⚠ WARNING: This will reset the document and clear all processing data!');
console.log(' The document will need to be reprocessed from the beginning.');
process.exit(1);
}
resetStuckDocument(documentId);