clean up proxyManager
This commit is contained in:
parent
da916222c1
commit
76d55fe35f
10 changed files with 38 additions and 438 deletions
|
|
@ -7,7 +7,7 @@ import {
|
|||
handlerRegistry,
|
||||
type HandlerConfigWithSchedule,
|
||||
} from '@stock-bot/queue';
|
||||
import { ProxyManager } from '@stock-bot/utils';
|
||||
import { updateProxies } from '@stock-bot/utils';
|
||||
|
||||
const logger = getLogger('webshare-provider');
|
||||
|
||||
|
|
@ -28,7 +28,7 @@ export function initializeWebShareProvider() {
|
|||
|
||||
if (proxies.length > 0) {
|
||||
// Update the centralized proxy manager
|
||||
await ProxyManager.getInstance().updateProxies(proxies);
|
||||
await updateProxies(proxies);
|
||||
|
||||
logger.info('Updated proxy manager with WebShare proxies', {
|
||||
count: proxies.length,
|
||||
|
|
@ -57,40 +57,6 @@ export function initializeWebShareProvider() {
|
|||
};
|
||||
}
|
||||
}),
|
||||
|
||||
'validate-proxies': createJobHandler(async () => {
|
||||
logger.info('Validating existing proxies');
|
||||
const { validateStoredProxies } = await import('./webshare.tasks');
|
||||
|
||||
try {
|
||||
const validationResults = await validateStoredProxies();
|
||||
|
||||
// Update proxy manager with validated proxies
|
||||
await ProxyManager.getInstance().updateProxies(validationResults.workingProxies);
|
||||
|
||||
logger.info('Proxy validation completed', {
|
||||
totalChecked: validationResults.totalChecked,
|
||||
workingCount: validationResults.workingCount,
|
||||
successRate: ((validationResults.workingCount / validationResults.totalChecked) * 100).toFixed(1) + '%',
|
||||
});
|
||||
|
||||
return validationResults;
|
||||
} catch (error) {
|
||||
logger.error('Failed to validate proxies', { error });
|
||||
return {
|
||||
workingProxies: [],
|
||||
totalChecked: 0,
|
||||
workingCount: 0,
|
||||
error: error instanceof Error ? error.message : 'Unknown error',
|
||||
};
|
||||
}
|
||||
}),
|
||||
|
||||
'get-stats': createJobHandler(async () => {
|
||||
const stats = ProxyManager.getInstance().getStats();
|
||||
logger.info('Proxy manager statistics', stats);
|
||||
return stats;
|
||||
}),
|
||||
},
|
||||
|
||||
scheduledJobs: [
|
||||
|
|
@ -103,22 +69,6 @@ export function initializeWebShareProvider() {
|
|||
description: 'Fetch fresh proxies from WebShare API',
|
||||
immediately: true, // Run on startup
|
||||
},
|
||||
{
|
||||
type: 'webshare-validate',
|
||||
operation: 'validate-proxies',
|
||||
payload: {},
|
||||
cronPattern: '0 */2 * * *', // Every 2 hours
|
||||
priority: 4,
|
||||
description: 'Validate and clean existing proxies',
|
||||
},
|
||||
{
|
||||
type: 'webshare-stats',
|
||||
operation: 'get-stats',
|
||||
payload: {},
|
||||
cronPattern: '0 * * * *', // Every hour
|
||||
priority: 5,
|
||||
description: 'Log proxy manager statistics',
|
||||
},
|
||||
],
|
||||
};
|
||||
|
||||
|
|
@ -126,20 +76,7 @@ export function initializeWebShareProvider() {
|
|||
logger.debug('WebShare provider registered successfully');
|
||||
}
|
||||
|
||||
// Legacy function for backward compatibility - now uses centralized proxy manager
|
||||
export async function getProxy(): Promise<string | null> {
|
||||
const proxy = ProxyManager.getInstance().getRandomProxy();
|
||||
if (!proxy) {
|
||||
return null;
|
||||
}
|
||||
|
||||
// Convert ProxyInfo back to string format for backward compatibility
|
||||
const auth = proxy.username && proxy.password ? `${proxy.username}:${proxy.password}@` : '';
|
||||
return `${proxy.protocol}://${auth}${proxy.host}:${proxy.port}`;
|
||||
}
|
||||
|
||||
export const webShareProvider = {
|
||||
initialize: initializeWebShareProvider,
|
||||
getProxy,
|
||||
};
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue