Skip to content

Commit 37c5139

Browse files
committed
Issue #571/#595 basic docs for JobDatabaseInterface feature
1 parent 1ce55e5 commit 37c5139

File tree

3 files changed

+46
-6
lines changed

3 files changed

+46
-6
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1212
- Add experimental `openeo.testing.results` subpackage with reusable test utilities for comparing batch job results with reference data
1313
- `MultiBackendJobManager`: add initial support for storing job metadata in Parquet file (instead of CSV) ([#571](https://github.com/Open-EO/openeo-python-client/issues/571))
1414
- Add `Connection.authenticate_oidc_access_token()` to set up authorization headers with an access token that is obtained "out-of-band" ([#598](https://github.com/Open-EO/openeo-python-client/issues/598))
15+
- Add `JobDatabaseInterface` to allow custom job metadata storage with `MultiBackendJobManager` ([#571](https://github.com/Open-EO/openeo-python-client/issues/571))
1516

1617
### Changed
1718

docs/cookbook/job_manager.rst

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,13 @@ Multi Backend Job Manager
55
.. warning::
66
This is a new experimental API, subject to change.
77

8-
.. automodule:: openeo.extra.job_management
9-
:members: MultiBackendJobManager, ignore_connection_errors
8+
.. autoclass:: openeo.extra.job_management.MultiBackendJobManager
9+
:members:
10+
11+
.. autoclass:: openeo.extra.job_management.JobDatabaseInterface
12+
:members:
13+
14+
.. autoclass:: openeo.extra.job_management.CsvJobDatabase
15+
:members: __init__
16+
17+
.. autoclass:: openeo.extra.job_management.ParquetJobDatabase

openeo/extra/job_management.py

Lines changed: 35 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@ class JobDatabaseInterface(metaclass=abc.ABCMeta):
3838
Interface for a database of job metadata to use with the :py:class:`MultiBackendJobManager`,
3939
allowing to regularly persist the job metadata while polling the job statuses
4040
and resume/restart the job tracking after it was interrupted.
41+
42+
.. versionadded:: 0.31.0
4143
"""
4244

4345
@abc.abstractmethod
@@ -47,12 +49,20 @@ def exists(self) -> bool:
4749

4850
@abc.abstractmethod
4951
def read(self) -> pd.DataFrame:
50-
"""Read job data from the database as pandas DataFrame."""
52+
"""
53+
Read job data from the database as pandas DataFrame.
54+
55+
:return: loaded job data.
56+
"""
5157
...
5258

5359
@abc.abstractmethod
5460
def persist(self, df: pd.DataFrame):
55-
"""Store job data to the database."""
61+
"""
62+
Store job data to the database.
63+
64+
:param df: job data to store.
65+
"""
5666
...
5767

5868

@@ -511,17 +521,26 @@ def _format_usage_stat(job_metadata: dict, field: str) -> str:
511521

512522

513523
@contextlib.contextmanager
514-
def ignore_connection_errors(context: Optional[str] = None):
524+
def ignore_connection_errors(context: Optional[str] = None, sleep: int = 5):
515525
"""Context manager to ignore connection errors."""
526+
# TODO: move this out of this module and make it a more public utility?
516527
try:
517528
yield
518529
except requests.exceptions.ConnectionError as e:
519530
_log.warning(f"Ignoring connection error (context {context or 'n/a'}): {e}")
520531
# Back off a bit
521-
time.sleep(5)
532+
time.sleep(sleep)
522533

523534

524535
class CsvJobDatabase(JobDatabaseInterface):
536+
"""
537+
Persist/load job metadata with a CSV file.
538+
539+
:implements: :py:class:`JobDatabaseInterface`
540+
:param path: Path to local CSV file.
541+
542+
.. versionadded:: 0.31.0
543+
"""
525544
def __init__(self, path: Union[str, Path]):
526545
self.path = Path(path)
527546

@@ -552,6 +571,18 @@ def persist(self, df: pd.DataFrame):
552571

553572

554573
class ParquetJobDatabase(JobDatabaseInterface):
574+
"""
575+
Persist/load job metadata with a Parquet file.
576+
577+
:implements: :py:class:`JobDatabaseInterface`
578+
:param path: Path to the Parquet file.
579+
580+
.. versionadded:: 0.31.0
581+
582+
.. note::
583+
Support for Parquet files depends on the ``pyarrow`` package
584+
as :ref:`optional dependency <installation-optional-dependencies>`.
585+
"""
555586
def __init__(self, path: Union[str, Path]):
556587
self.path = Path(path)
557588

0 commit comments

Comments
 (0)