-
Notifications
You must be signed in to change notification settings - Fork 47
Issue816 threadeddownload #836
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
base: master
Are you sure you want to change the base?
Changes from 11 commits
17d90a7
d22ac20
7acc043
246ac2f
d67fdd6
2973bee
0e7c4f5
8ccb442
855a393
e2b6ab8
dc75ca8
4fc299d
382eae4
ab9914a
1fce77b
21992fa
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -7,7 +7,9 @@ | |
| from abc import ABC, abstractmethod | ||
| from dataclasses import dataclass, field | ||
| from typing import Any, Dict, List, Optional, Tuple, Union | ||
| from pathlib import Path | ||
|
|
||
| import json | ||
| import urllib3.util | ||
|
|
||
| import openeo | ||
|
|
@@ -140,7 +142,46 @@ def execute(self) -> _TaskResult: | |
| stats_update={"start_job error": 1}, | ||
| ) | ||
|
|
||
| class _JobDownloadTask(ConnectedTask): | ||
| """ | ||
| Task for downloading job results and metadata. | ||
|
|
||
| :param download_dir: | ||
| Root directory where job results and metadata will be downloaded. | ||
| """ | ||
| def __init__(self, download_dir: Path, **kwargs): | ||
| super().__init__(**kwargs) | ||
| object.__setattr__(self, 'download_dir', download_dir) | ||
HansVRP marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| def execute(self) -> _TaskResult: | ||
| try: | ||
| job = self.get_connection(retry=True).job(self.job_id) | ||
|
|
||
| # Download results | ||
| job.get_results().download_files(target=self.download_dir) | ||
|
|
||
| # Download metadata | ||
| job_metadata = job.describe() | ||
| metadata_path = self.download_dir / f"job_{self.job_id}.json" | ||
| with metadata_path.open("w", encoding="utf-8") as f: | ||
| json.dump(job_metadata, f, ensure_ascii=False) | ||
|
|
||
| _log.info(f"Job {self.job_id!r} results downloaded successfully") | ||
| return _TaskResult( | ||
| job_id=self.job_id, | ||
| df_idx=self.df_idx, | ||
| db_update={}, #TODO consider db updates? | ||
| stats_update={"job download": 1}, | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. you probably also want to keep track of the number of files downloaded, not just the number of jobs that were downloaded from |
||
| ) | ||
| except Exception as e: | ||
| _log.error(f"Failed to download results for job {self.job_id!r}: {e!r}") | ||
| return _TaskResult( | ||
| job_id=self.job_id, | ||
| df_idx=self.df_idx, | ||
| db_update={}, | ||
| stats_update={"job download error": 1}, | ||
| ) | ||
|
|
||
| class _JobManagerWorkerThreadPool: | ||
| """ | ||
| Thread pool-based worker that manages the execution of asynchronous tasks. | ||
|
|
@@ -207,6 +248,10 @@ def process_futures(self, timeout: Union[float, None] = 0) -> Tuple[List[_TaskRe | |
|
|
||
| self._future_task_pairs = to_keep | ||
| return results, len(to_keep) | ||
|
|
||
| def num_pending_tasks(self) -> int: | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. abbreviating "number" to "num" is a bit off brand with the rest of the openEO client API. |
||
| """Return the number of tasks that are still pending (not completed).""" | ||
| return len(self._future_task_pairs) | ||
|
|
||
| def shutdown(self) -> None: | ||
| """Shuts down the thread pool gracefully.""" | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.