0
0
mirror of https://github.com/renovatebot/renovate.git synced 2024-12-22 13:38:32 +00:00
renovatebot_renovate/lib/util/http/queue.ts
Sergei Zharinov 8d183d6b25
feat(http): Force default rate limits for some known hosts (#30207)
Co-authored-by: HonkingGoose <34918129+HonkingGoose@users.noreply.github.com>
Co-authored-by: Michael Kriese <michael.kriese@visualon.de>
2024-07-22 16:59:29 +00:00

35 lines
936 B
TypeScript

import PQueue from 'p-queue';
import { logger } from '../../logger';
import { parseUrl } from '../url';
import { getConcurrentRequestsLimit } from './rate-limits';
const hostQueues = new Map<string, PQueue | null>();
export function getQueue(url: string): PQueue | null {
const host = parseUrl(url)?.host;
if (!host) {
// should never happen
logger.debug(`No host on ${url}`);
return null;
}
let queue = hostQueues.get(host);
if (queue === undefined) {
queue = null; // null represents "no queue", as opposed to undefined
const concurrency = getConcurrentRequestsLimit(url);
if (concurrency) {
logger.debug(`Using queue: host=${host}, concurrency=${concurrency}`);
queue = new PQueue({ concurrency });
} else {
logger.trace({ host }, 'No concurrency limits');
}
}
hostQueues.set(host, queue);
return queue;
}
export function clear(): void {
hostQueues.clear();
}