work on proxy
This commit is contained in:
parent
d67d07cba6
commit
2f070d73f9
6 changed files with 73 additions and 86 deletions
|
|
@ -3,13 +3,16 @@ import { getLogger } from '@stock-bot/logger';
|
|||
|
||||
// Initialize logger for the demo
|
||||
const logger = getLogger('proxy-demo');
|
||||
console.log('🔧 Starting proxy demo...');
|
||||
/**
|
||||
* Example: Custom proxy source with enhanced logging
|
||||
*/
|
||||
async function demonstrateCustomProxySource() {
|
||||
console.log('🔧 Demonstrating!');
|
||||
logger.info('🔧 Demonstrating custom proxy source...');
|
||||
|
||||
try {
|
||||
console.log('🔧 Demonstrating 1');
|
||||
await proxyService.fetchProxiesFromSources();
|
||||
console.log('🔧 Demonstrating custom proxy source is DONE!');
|
||||
} catch (error) {
|
||||
|
|
@ -19,76 +22,3 @@ async function demonstrateCustomProxySource() {
|
|||
}
|
||||
}
|
||||
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);
|
||||
// // }
|
||||
|
|
|
|||
|
|
@ -15,6 +15,7 @@ export class ProxyService {
|
|||
private readonly CHECK_URL = 'https://proxy-detection.stare.gg/?api_key=bd406bf53ddc6abe1d9de5907830a955';
|
||||
private readonly PROXY_SOURCES = [
|
||||
{url: 'https://raw.githubusercontent.com/prxchk/proxy-list/main/http.txt',protocol: 'http', },
|
||||
{url: 'https://raw.githubusercontent.com/casals-ar/proxy-list/main/http',protocol: 'http', },
|
||||
{url: 'https://raw.githubusercontent.com/MuRongPIG/Proxy-Master/main/http.txt',protocol: 'http', },
|
||||
{url: 'https://raw.githubusercontent.com/vakhov/fresh-proxy-list/master/http.txt',protocol: 'http', },
|
||||
{url: 'https://raw.githubusercontent.com/sunny9577/proxy-scraper/master/proxies.txt',protocol: 'http', },
|
||||
|
|
@ -146,9 +147,7 @@ export class ProxyService {
|
|||
this.logger.error(`Error fetching proxies from ${source.url}`, error);
|
||||
return [];
|
||||
}
|
||||
|
||||
|
||||
this.logger.info(`Total proxies fetched: ${allProxies.length}`);
|
||||
// this.logger.info(`Total proxies fetched: ${allProxies.length}`);
|
||||
return allProxies;
|
||||
}
|
||||
|
||||
|
|
@ -164,6 +163,10 @@ export class ProxyService {
|
|||
* Check if a proxy is working
|
||||
*/
|
||||
async checkProxy(proxy: ProxyInfo): Promise<ProxyInfo> {
|
||||
this.logger.debug('Checking Proxy : ', {
|
||||
host: proxy.host,
|
||||
port: proxy.port,
|
||||
});
|
||||
// console.log('Checking proxy:', `${proxy.protocol}://${proxy.host}:${proxy.port}`, this.concurrencyLimit.activeCount, this.concurrencyLimit.pendingCount);
|
||||
try {
|
||||
|
||||
|
|
@ -179,7 +182,8 @@ export class ProxyService {
|
|||
...proxy,
|
||||
isWorking,
|
||||
checkedAt: new Date(),
|
||||
responseTime: response.responseTime, };
|
||||
responseTime: response.responseTime,
|
||||
};
|
||||
// console.log('Proxy check result:', proxy);
|
||||
if (isWorking && JSON.stringify(response.data).includes(this.CHECK_IP)) {
|
||||
await this.cache.set(`${this.CACHE_KEY}:${proxy.protocol}://${proxy.host}:${proxy.port}`, result, this.CACHE_TTL);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue