testing
This commit is contained in:
parent
413b133a1f
commit
5d8b102422
2 changed files with 12 additions and 8 deletions
|
|
@ -7,7 +7,7 @@ export class ProxyService {
|
|||
private logger = new Logger('proxy-service');
|
||||
private cache: CacheProvider = createCache('hybrid');
|
||||
private httpClient: HttpClient;
|
||||
private readonly concurrencyLimit = pLimit(250);
|
||||
private readonly concurrencyLimit = pLimit(200);
|
||||
private readonly CACHE_KEY = 'proxy';
|
||||
private readonly CACHE_TTL = 86400; // 24 hours
|
||||
private readonly CHECK_TIMEOUT = 7000;
|
||||
|
|
@ -163,12 +163,15 @@ export class ProxyService {
|
|||
* Check if a proxy is working
|
||||
*/
|
||||
async checkProxy(proxy: ProxyInfo): Promise<ProxyInfo> {
|
||||
let success = false;
|
||||
this.logger.debug('Checking Proxy : ', {
|
||||
protocol: proxy.protocol,
|
||||
host: proxy.host,
|
||||
port: proxy.port,
|
||||
});
|
||||
// console.log('Checking proxy:', `${proxy.protocol}://${proxy.host}:${proxy.port}`, this.concurrencyLimit.activeCount, this.concurrencyLimit.pendingCount);
|
||||
try {
|
||||
|
||||
|
||||
// Test the proxy
|
||||
const response = await this.httpClient.get(this.CHECK_URL, {
|
||||
|
|
@ -186,11 +189,11 @@ export class ProxyService {
|
|||
};
|
||||
// console.log('Proxy check result:', proxy);
|
||||
if (isWorking && !JSON.stringify(response.data).includes(this.CHECK_IP)) {
|
||||
success = true
|
||||
await this.cache.set(`${this.CACHE_KEY}:${proxy.protocol}://${proxy.host}:${proxy.port}`, result, this.CACHE_TTL);
|
||||
}
|
||||
// else { // TODO
|
||||
// await this.cache.del(`${this.CACHE_KEY}:${proxy.protocol}://${proxy.host}:${proxy.port}`);
|
||||
// }
|
||||
} else {
|
||||
await this.cache.del(`${this.CACHE_KEY}:${proxy.protocol}://${proxy.host}:${proxy.port}`);
|
||||
}
|
||||
|
||||
this.logger.debug('Proxy check completed', {
|
||||
host: proxy.host,
|
||||
|
|
@ -212,7 +215,8 @@ export class ProxyService {
|
|||
|
||||
// Cache failed result for shorter time
|
||||
// await this.cache.set(cacheKey, result, 300); // 5 minutes
|
||||
// await this.cache.del(`${this.CACHE_KEY}:${proxy.protocol}://${proxy.host}:${proxy.port}`);
|
||||
if(!success) // If the proxy check failed, remove it from cache - success is here cause i think abort signal fails sometimes
|
||||
await this.cache.del(`${this.CACHE_KEY}:${proxy.protocol}://${proxy.host}:${proxy.port}`);
|
||||
|
||||
this.logger.debug('Proxy check failed', {
|
||||
host: proxy.host,
|
||||
|
|
|
|||
|
|
@ -80,13 +80,13 @@ export class HttpClient {
|
|||
const controller = new AbortController();
|
||||
const startTime = Date.now();
|
||||
let timeoutId: NodeJS.Timeout | undefined;
|
||||
|
||||
|
||||
// Set up timeout
|
||||
// Create a timeout promise that will reject
|
||||
const timeoutPromise = new Promise<never>((_, reject) => {
|
||||
timeoutId = setTimeout(() => {
|
||||
const elapsed = Date.now() - startTime;
|
||||
this.logger?.warn('Request timeout triggered', {
|
||||
this.logger?.debug('Request timeout triggered', {
|
||||
url: config.url,
|
||||
method: config.method,
|
||||
timeout,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue