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

fix(scraper): Fix bulk analyzis helper to return a sync Generator #99

Merged
merged 3 commits into from
Aug 30, 2024
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
17 changes: 7 additions & 10 deletions bases/ecoindex/cli/app.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
from asyncio import run
from datetime import datetime
from multiprocessing import cpu_count
from os.path import dirname
Expand Down Expand Up @@ -225,15 +224,13 @@ def analyze(
count_errors = 0
task = progress.add_task("Processing", total=len(urls) * len(window_sizes))

analysis_results = run(
bulk_analysis(
max_workers=max_workers,
urls=urls,
window_sizes=window_sizes,
wait_after_scroll=wait_after_scroll,
wait_before_scroll=wait_before_scroll,
logger=logger,
)
analysis_results = bulk_analysis(
max_workers=max_workers,
urls=urls,
window_sizes=window_sizes,
wait_after_scroll=wait_after_scroll,
wait_before_scroll=wait_before_scroll,
logger=logger,
)

for result, success in analysis_results:
Expand Down
6 changes: 3 additions & 3 deletions components/ecoindex/scraper/helper.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from asyncio import run
from concurrent.futures import ThreadPoolExecutor, as_completed
from typing import AsyncGenerator
from typing import Generator

from ecoindex.models.compute import Result, WindowSize
from ecoindex.scraper.scrap import EcoindexScraper
Expand Down Expand Up @@ -40,14 +40,14 @@ def run_page_analysis(
)


async def bulk_analysis(
def bulk_analysis(
max_workers,
urls,
window_sizes,
wait_after_scroll: int = 0,
wait_before_scroll: int = 0,
logger=None,
) -> AsyncGenerator[tuple[Result, bool], None]:
) -> Generator[tuple[Result, bool], None, None]:
with ThreadPoolExecutor(max_workers=max_workers) as executor:
future_to_analysis = {}

Expand Down
4 changes: 2 additions & 2 deletions projects/ecoindex_cli/dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM python:3.12-slim as requirements-stage
FROM python:3.12-slim AS requirements-stage

WORKDIR /tmp

Expand All @@ -8,7 +8,7 @@ RUN poetry export --output=requirements.txt --without-hashes


FROM python:3.12-slim

ARG wheel=ecoindex_cli-2.26.0a0-py3-none-any.whl
ENV DOCKER_CONTAINER=True

Expand Down
Loading
Loading