avoid excessive vpn restarts
This commit is contained in:
parent
62a99c028f
commit
b8a2a5365a
36
index.ts
36
index.ts
|
|
@ -23,6 +23,8 @@ ffmpeg.setFfmpegPath('/usr/local/bin/ffmpeg')
|
||||||
const maxRetries = 5
|
const maxRetries = 5
|
||||||
const innertubePool = createInnertubePool(parseInt(Bun.env.INNERTUBE_POOL_SIZE || '4'))
|
const innertubePool = createInnertubePool(parseInt(Bun.env.INNERTUBE_POOL_SIZE || '4'))
|
||||||
|
|
||||||
|
let consecutiveFailures = 0;
|
||||||
|
|
||||||
app.get('/health', async (req, res) => {
|
app.get('/health', async (req, res) => {
|
||||||
try {
|
try {
|
||||||
const urls = ['/video/sRMMwpDTs5k', '/channel/UCEcryET60dO0HgVGjZ6WnXA', '/videos/UCEcryET60dO0HgVGjZ6WnXA']
|
const urls = ['/video/sRMMwpDTs5k', '/channel/UCEcryET60dO0HgVGjZ6WnXA', '/videos/UCEcryET60dO0HgVGjZ6WnXA']
|
||||||
|
|
@ -38,15 +40,37 @@ app.get('/health', async (req, res) => {
|
||||||
|
|
||||||
const isHealthy = results.every(result => result.status === 'healthy');
|
const isHealthy = results.every(result => result.status === 'healthy');
|
||||||
if (isHealthy) {
|
if (isHealthy) {
|
||||||
res.status(200).json({ message: 'All endpoints are healthy', results });
|
consecutiveFailures = 0;
|
||||||
|
res.status(200).json({ message: 'All endpoints are healthy', results, consecutiveFailures });
|
||||||
} else {
|
} else {
|
||||||
res.status(500).json({ error: 'Health check failed', results });
|
consecutiveFailures++;
|
||||||
switchIps()
|
console.log(`Health check failed. Consecutive failures: ${consecutiveFailures}`);
|
||||||
|
|
||||||
|
if (consecutiveFailures === 3) {
|
||||||
|
console.log('3 consecutive failures reached. Switching IP in background...');
|
||||||
|
switchIps().catch(err => console.error('Failed to switch IP:', err));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (consecutiveFailures >= 6) {
|
||||||
|
res.status(500).json({ error: 'Health check failed', results, consecutiveFailures });
|
||||||
|
} else {
|
||||||
|
res.status(200).json({ message: 'Health check failing but within allowed threshold', results, consecutiveFailures });
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} catch (error:any) {
|
} catch (error:any) {
|
||||||
console.error('Health check failed:', error.message);
|
consecutiveFailures++;
|
||||||
switchIps()
|
console.error(`Health check error. Consecutive failures: ${consecutiveFailures}. Error:`, error.message);
|
||||||
res.status(500).json({ error: 'Health check failed', results: [], errorMessage: error.message });
|
|
||||||
|
if (consecutiveFailures === 3) {
|
||||||
|
console.log('3 consecutive failures reached (from error). Switching IP in background...');
|
||||||
|
switchIps().catch(err => console.error('Failed to switch IP:', err));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (consecutiveFailures >= 6) {
|
||||||
|
res.status(500).json({ error: 'Health check failed', results: [], errorMessage: error.message, consecutiveFailures });
|
||||||
|
} else {
|
||||||
|
res.status(200).json({ message: 'Health check failing but within allowed threshold (error)', errorMessage: error.message, consecutiveFailures });
|
||||||
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue