Add runAllConcurrent to ProviderControls

This commit is contained in:
TheTank 2026-02-04 15:20:42 -05:00
parent 44c25302c0
commit f0dcba4606
2 changed files with 13 additions and 2 deletions

View file

@ -6,7 +6,7 @@ import { makeFetcher } from '@/fetchers/common';
import { Fetcher } from '@/fetchers/types';
import { Embed, EmbedOutput, Sourcerer, SourcererOutput } from '@/providers/base';
import { scrapeIndividualEmbed, scrapeInvidualSource } from '@/runners/individualRunner';
import { RunOutput, runAllProviders } from '@/runners/runner';
import { RunOutput, runAllProviders, runAllProvidersConcurrent } from '@/runners/runner';
export interface ProviderControlsInput {
fetcher: Fetcher;
@ -15,6 +15,7 @@ export interface ProviderControlsInput {
sources: Sourcerer[];
embeds: Embed[];
proxyStreams?: boolean; // temporary
concurrency?: number;
}
export interface RunnerOptions {
@ -72,6 +73,9 @@ export interface ProviderControls {
// returns the stream, or null if none found
runAll(runnerOps: RunnerOptions): Promise<RunOutput | null>;
// Run all providers concurrently. in order of rank (highest first)
runAllConcurrent(runnerOps: RunnerOptions): Promise<RunOutput | null>;
// Run a specific source scraper
runSourceScraper(runnerOps: SourceRunnerOptions): Promise<SourcererOutput>;
@ -99,6 +103,7 @@ export function makeControls(ops: ProviderControlsInput): ProviderControls {
fetcher: makeFetcher(ops.fetcher),
proxiedFetcher: makeFetcher(ops.proxiedFetcher ?? ops.fetcher),
proxyStreams: ops.proxyStreams,
concurrency: ops.concurrency ?? 3, // default to 3 workers
};
return {
@ -108,6 +113,12 @@ export function makeControls(ops: ProviderControlsInput): ProviderControls {
...runnerOps,
});
},
runAllConcurrent(runnerOps) {
return runAllProvidersConcurrent(list, {
...providerRunnerOps,
...runnerOps,
});
},
runSourceScraper(runnerOps) {
return scrapeInvidualSource(list, {
...providerRunnerOps,

View file

@ -204,7 +204,7 @@ export async function runAllProviders(list: ProviderList, ops: ProviderRunnerOpt
}
export async function runAllProvidersConcurrent(list: ProviderList, ops: ProviderRunnerOptions): Promise<RunOutput | null> {
const concurrency = ops.concurrency ?? 3; // default to 3 workers
const concurrency = ops.concurrency ?? 3;
const sources = reorderOnIdList(ops.sourceOrder ?? [], list.sources).filter((source) => {
if (ops.media.type === 'movie') return !!source.scrapeMovie;