fixed proxy started working on new qm
This commit is contained in:
parent
d989c0c814
commit
e5f505335c
12 changed files with 375 additions and 115 deletions
|
|
@ -73,53 +73,20 @@ export class ProxyManager {
|
|||
return proxyUrl;
|
||||
}
|
||||
/**
|
||||
* Get a random working proxy from the available pool (synchronous)
|
||||
* Get proxy info for the current proxy in rotation (synchronous)
|
||||
*/
|
||||
getRandomProxy(): ProxyInfo | null {
|
||||
// Ensure initialized
|
||||
if (!this.isInitialized) {
|
||||
throw new Error('ProxyManager not initialized');
|
||||
}
|
||||
|
||||
// Return null if no proxies available
|
||||
getProxyInfo(): ProxyInfo | null {
|
||||
if (this.proxies.length === 0) {
|
||||
this.logger.warn('No proxies available in memory');
|
||||
return null;
|
||||
}
|
||||
|
||||
// Filter for working proxies (not explicitly marked as non-working)
|
||||
const workingProxies = this.proxies.filter(proxy => proxy.isWorking !== false);
|
||||
|
||||
if (workingProxies.length === 0) {
|
||||
this.logger.warn('No working proxies available');
|
||||
return null;
|
||||
}
|
||||
|
||||
// Return random proxy with preference for recently successful ones
|
||||
const sortedProxies = workingProxies.sort((a, b) => {
|
||||
// Prefer proxies with better success rates
|
||||
const aRate = a.successRate || 0;
|
||||
const bRate = b.successRate || 0;
|
||||
return bRate - aRate;
|
||||
});
|
||||
|
||||
// Take from top 50% of best performing proxies
|
||||
const topProxies = sortedProxies.slice(0, Math.max(1, Math.floor(sortedProxies.length * 0.5)));
|
||||
const selectedProxy = topProxies[Math.floor(Math.random() * topProxies.length)];
|
||||
|
||||
if (!selectedProxy) {
|
||||
this.logger.warn('No proxy selected from available pool');
|
||||
return null;
|
||||
}
|
||||
|
||||
this.logger.debug('Selected proxy', {
|
||||
host: selectedProxy.host,
|
||||
port: selectedProxy.port,
|
||||
successRate: selectedProxy.successRate,
|
||||
totalAvailable: workingProxies.length,
|
||||
});
|
||||
|
||||
return selectedProxy;
|
||||
// Use same rotation logic as getProxy() to ensure consistency
|
||||
// Note: We don't increment the index here since getProxy() already does that
|
||||
const currentIndex = this.proxyIndex > 0 ? this.proxyIndex - 1 : this.proxies.length - 1;
|
||||
const proxyInfo = this.proxies[currentIndex];
|
||||
|
||||
return proxyInfo || null;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue