working on proxy service
This commit is contained in:
parent
1395e448b7
commit
3d9eb2ec9b
3 changed files with 88 additions and 87 deletions
|
|
@ -97,7 +97,7 @@ async function demonstrateCustomProxySource() {
|
|||
|
||||
const customSources : ProxySource[] = [
|
||||
{
|
||||
url: 'https://raw.githubusercontent.com/monosans/proxy-list/main/proxies/http.txt',
|
||||
url: 'https://raw.githubusercontent.com/TheSpeedX/PROXY-List/refs/heads/master/http.txt',
|
||||
protocol: 'http'
|
||||
}
|
||||
];
|
||||
|
|
@ -114,82 +114,77 @@ async function demonstrateCustomProxySource() {
|
|||
});
|
||||
}
|
||||
}
|
||||
|
||||
// Export functions for use in other files
|
||||
export {
|
||||
// demonstrateProxyService,
|
||||
demonstrateCustomProxySource
|
||||
};
|
||||
|
||||
// Execute the demo with enhanced logging and graceful shutdown
|
||||
logger.info('🚀 Starting enhanced proxy demo...');
|
||||
|
||||
// Configure graceful shutdown
|
||||
setShutdownTimeout(15000); // 15 seconds shutdown timeout
|
||||
|
||||
// Register shutdown handlers
|
||||
onShutdown(async () => {
|
||||
logger.info('🔧 Cleaning up proxy service...');
|
||||
try {
|
||||
// Clean up proxy service resources if needed
|
||||
// await proxyService.shutdown();
|
||||
logger.info('✅ Proxy service cleanup completed');
|
||||
} catch (error) {
|
||||
logger.error('❌ Proxy service cleanup failed', error);
|
||||
}
|
||||
});
|
||||
|
||||
onShutdown(async () => {
|
||||
logger.info('🔧 Shutting down loggers...');
|
||||
try {
|
||||
await shutdownLoggers();
|
||||
console.log('✅ Logger shutdown completed');
|
||||
} catch (error) {
|
||||
console.error('❌ Logger shutdown failed:', error);
|
||||
}
|
||||
});
|
||||
|
||||
onShutdown(async () => {
|
||||
logger.info('🔧 Performing final cleanup...');
|
||||
// Any additional cleanup can go here
|
||||
await new Promise(resolve => setTimeout(resolve, 1000)); // Simulate cleanup work
|
||||
logger.info('✅ Final cleanup completed');
|
||||
});
|
||||
|
||||
// Demonstrate graceful shutdown by setting up a timer to shutdown after demo
|
||||
const shutdownTimer = setTimeout(() => {
|
||||
logger.info('⏰ Demo timeout reached, initiating graceful shutdown...');
|
||||
process.kill(process.pid, 'SIGTERM');
|
||||
}, 20000); // Shutdown after 20 seconds
|
||||
|
||||
// Clear timer if demo completes early
|
||||
const clearShutdownTimer = () => {
|
||||
clearTimeout(shutdownTimer);
|
||||
logger.info('⏰ Demo completed, canceling automatic shutdown timer');
|
||||
};
|
||||
|
||||
demonstrateCustomProxySource()
|
||||
.then(() => {
|
||||
logger.info('🎉 Proxy demo completed successfully!');
|
||||
clearShutdownTimer();
|
||||
|
||||
// Demonstrate manual shutdown after a short delay
|
||||
setTimeout(() => {
|
||||
logger.info('🔄 Demonstrating manual graceful shutdown in 3 seconds...');
|
||||
setTimeout(() => {
|
||||
process.kill(process.pid, 'SIGTERM');
|
||||
}, 3000);
|
||||
}, 2000);
|
||||
})
|
||||
.catch((error) => {
|
||||
logger.error('💥 Proxy demo failed', error);
|
||||
clearShutdownTimer();
|
||||
setTimeout(() => process.exit(1), 1000);
|
||||
});
|
||||
|
||||
// If this file is run directly, execute the demo
|
||||
// if (import.meta.main) {
|
||||
// demonstrateProxyService()
|
||||
// demonstrateCustomProxySource()
|
||||
// .catch(console.error);
|
||||
// }
|
||||
// // Execute the demo with enhanced logging and graceful shutdown
|
||||
// logger.info('🚀 Starting enhanced proxy demo...');
|
||||
|
||||
// // Configure graceful shutdown
|
||||
// setShutdownTimeout(15000); // 15 seconds shutdown timeout
|
||||
|
||||
// // Register shutdown handlers
|
||||
// onShutdown(async () => {
|
||||
// logger.info('🔧 Cleaning up proxy service...');
|
||||
// try {
|
||||
// // Clean up proxy service resources if needed
|
||||
// // await proxyService.shutdown();
|
||||
// logger.info('✅ Proxy service cleanup completed');
|
||||
// } catch (error) {
|
||||
// logger.error('❌ Proxy service cleanup failed', error);
|
||||
// }
|
||||
// });
|
||||
|
||||
// onShutdown(async () => {
|
||||
// logger.info('🔧 Shutting down loggers...');
|
||||
// try {
|
||||
// await shutdownLoggers();
|
||||
// console.log('✅ Logger shutdown completed');
|
||||
// } catch (error) {
|
||||
// console.error('❌ Logger shutdown failed:', error);
|
||||
// }
|
||||
// });
|
||||
|
||||
// onShutdown(async () => {
|
||||
// logger.info('🔧 Performing final cleanup...');
|
||||
// // Any additional cleanup can go here
|
||||
// await new Promise(resolve => setTimeout(resolve, 1000)); // Simulate cleanup work
|
||||
// logger.info('✅ Final cleanup completed');
|
||||
// });
|
||||
|
||||
// // Demonstrate graceful shutdown by setting up a timer to shutdown after demo
|
||||
// const shutdownTimer = setTimeout(() => {
|
||||
// logger.info('⏰ Demo timeout reached, initiating graceful shutdown...');
|
||||
// process.kill(process.pid, 'SIGTERM');
|
||||
// }, 20000); // Shutdown after 20 seconds
|
||||
|
||||
// // Clear timer if demo completes early
|
||||
// const clearShutdownTimer = () => {
|
||||
// clearTimeout(shutdownTimer);
|
||||
// logger.info('⏰ Demo completed, canceling automatic shutdown timer');
|
||||
// };
|
||||
|
||||
// demonstrateCustomProxySource()
|
||||
// .then(() => {
|
||||
// logger.info('🎉 Proxy demo completed successfully!');
|
||||
// clearShutdownTimer();
|
||||
|
||||
// // Demonstrate manual shutdown after a short delay
|
||||
// setTimeout(() => {
|
||||
// logger.info('🔄 Demonstrating manual graceful shutdown in 3 seconds...');
|
||||
// setTimeout(() => {
|
||||
// process.kill(process.pid, 'SIGTERM');
|
||||
// }, 3000);
|
||||
// }, 2000);
|
||||
// })
|
||||
// .catch((error) => {
|
||||
// logger.error('💥 Proxy demo failed', error);
|
||||
// clearShutdownTimer();
|
||||
// setTimeout(() => process.exit(1), 1000);
|
||||
// });
|
||||
|
||||
// // If this file is run directly, execute the demo
|
||||
// // if (import.meta.main) {
|
||||
// // demonstrateProxyService()
|
||||
// // demonstrateCustomProxySource()
|
||||
// // .catch(console.error);
|
||||
// // }
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue