-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
51 lines (45 loc) · 1.44 KB
/
index.js
File metadata and controls
51 lines (45 loc) · 1.44 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
require('dotenv').config();
const axios = require('axios');
async function pingRenderBackend() {
const RENDER_URL = process.env.RENDER_URL;
if (!RENDER_URL) {
console.error('Error: RENDER_URL environment variable is not set');
process.exit(1);
}
console.log(`Pinging Render backend at ${RENDER_URL}...`);
console.log(`Timestamp: ${new Date().toISOString()}`);
const maxRetries = 3;
const retryDelay = 5000;
for (let attempt = 1; attempt <= maxRetries; attempt++) {
try {
const startTime = Date.now();
const response = await axios.get(RENDER_URL, {
timeout: 30000, // 30-second timeout
});
const duration = Date.now() - startTime;
console.log(`Ping successful! Status: ${response.status}`);
console.log(`Response time: ${duration}ms`);
return response;
} catch (error) {
console.error(`Ping attempt ${attempt} failed: ${error.message}`);
if (attempt < maxRetries) {
console.log(`Retrying in ${retryDelay / 1000} seconds...`);
await new Promise((resolve) => setTimeout(resolve, retryDelay));
} else {
console.error('All retry attempts failed.');
process.exit(1);
}
}
}
}
// Execute ping and exit
(async () => {
try {
await pingRenderBackend();
console.log('Ping completed successfully');
process.exit(0);
} catch (error) {
console.error('Ping operation failed:', error.message);
process.exit(1);
}
})();