Files
cannaiq/backend/fix-stuck-job.js
2025-11-28 19:45:44 -07:00

39 lines
1021 B
JavaScript

const { Pool } = require('pg');
const pool = new Pool({
connectionString: process.env.DATABASE_URL || 'postgresql://kelly:kelly@localhost:5432/hub'
});
(async () => {
try {
// Check for stuck jobs
const result = await pool.query(`
SELECT id, status, total_proxies, tested_proxies, started_at
FROM proxy_test_jobs
WHERE status IN ('pending', 'running')
ORDER BY created_at DESC
`);
console.log('Found stuck jobs:', result.rows);
// Mark them as cancelled
if (result.rows.length > 0) {
await pool.query(`
UPDATE proxy_test_jobs
SET status = 'cancelled',
completed_at = CURRENT_TIMESTAMP,
updated_at = CURRENT_TIMESTAMP
WHERE status IN ('pending', 'running')
`);
console.log('✅ Cleaned up', result.rows.length, 'stuck jobs');
} else {
console.log('No stuck jobs found');
}
process.exit(0);
} catch (error) {
console.error('❌ Error:', error);
process.exit(1);
}
})();