Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat: Run orbit scrapping sequentially #9

Merged
merged 1 commit into from
Oct 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 7 additions & 4 deletions src/core/parsers/orbit/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ export class OrbitParser extends BaseParser {
const getRedisSubscriberResult = await RedisSingleton.getSubscriber();
if (getRedisSubscriberResult.result === "success") {
const betProviderConfig = getBetProviderConfigResult.value;
const results = betProviderConfig.games.map(async game => {

betProviderConfig.games.forEach(async game => {
await getRedisSubscriberResult.value.subscribe(getRedisHtmlParserChannelName(this.betProvider, game), message => {
const parsedMessage = JSON.parse(message) as RawHtmlForProcessingMessage;
logger.trace("Redis subscriber message received.", {
Expand All @@ -42,7 +43,7 @@ export class OrbitParser extends BaseParser {
});
return true;
});
await Promise.all(results);

return {result: "success", value: true};
} else {
logger.error("HTML parser failed to connect to redis subscriber for bet provider: ", this.betProvider.name);
Expand All @@ -68,7 +69,8 @@ export class OrbitParser extends BaseParser {
league: "N/A",
estimatedStartTimeUtc: item.estimatedStartTimeUtc,
meta: JSON.stringify({
oddsArray: item.oddsArray
oddsArray: item.oddsArray,
numBets: item.numBets
})
};
});
Expand All @@ -92,7 +94,8 @@ export class OrbitParser extends BaseParser {
league: "N/A",
estimatedStartTimeUtc: item.estimatedStartTimeUtc,
meta: JSON.stringify({
oddsArray: item.oddsArray
oddsArray: item.oddsArray,
numBets: item.numBets
})
}
});
Expand Down
18 changes: 14 additions & 4 deletions src/core/scrapping/orbit/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { BetProvider } from "../../../bet_providers";
import { OrbitProvider } from "../../../bet_providers/orbit";
import { RedisSingleton } from "../../../datastores/redis";
import { getRedisHtmlParserChannelName } from "../../../utils/redis";
import { PuppeteerPageLoadPolicy } from "../../../utils/types/common";
import { BetProviderGameConfig, PuppeteerPageLoadPolicy } from "../../../utils/types/common";
import { Result } from "../../../utils/types/result_type";
import { getHtmlForScrollingPage } from "../scrolling_scrapper";

Expand Down Expand Up @@ -39,7 +39,7 @@ export class OrbitScrapper extends BaseScrapper {
const betProviderConfig = getBetProviderConfigResult.value;
const browserInstance = await this.initializeBrowserInstance();

const result = betProviderConfig.games.map(async game => {
const results = await this.mapSeries(betProviderConfig.games, async (game) => {
const metadata = {
betProviderName: this.betProvider.name,
game: game.name,
Expand Down Expand Up @@ -75,10 +75,10 @@ export class OrbitScrapper extends BaseScrapper {
logger.error("An error occurred while fetching html for page", metadata);
}

return undefined;
return true;
});

await Promise.all(result);
logger.trace("Data fetch results: ", results);
await browserInstance.close();

return {
Expand All @@ -89,4 +89,14 @@ export class OrbitScrapper extends BaseScrapper {
return getRedisPublisherResult;
}
}

private async mapSeries(iterable: Iterable<BetProviderGameConfig>, fn: (game: BetProviderGameConfig) => Promise<boolean>) {
const results: boolean[] = [];

for (const x of iterable) {
results.push(await fn(x))
}

return results;
}
}