Skip to content

Commit 84d0a00

Browse files
authored
retry reading from job_metadata.json on NFS (#1300)
* accommodate for apparent NFS latency #1255 * avoid delay in non-result get job metadata #1255
1 parent efd754a commit 84d0a00

File tree

2 files changed

+11
-4
lines changed

2 files changed

+11
-4
lines changed

openeogeotrellis/backend.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
import pkg_resources
3333
import pystac
3434
import requests
35+
import reretry
3536
import shapely.geometry.base
3637
from deprecated import deprecated
3738
from geopyspark import LayerType, Pyramid, TiledRasterLayer
@@ -2830,6 +2831,12 @@ def load_results_metadata(self, job_id: str, user_id: str) -> dict:
28302831

28312832
return {}
28322833

2834+
@staticmethod
2835+
@reretry.retry(exceptions=FileNotFoundError, tries=5, delay=1, backoff=2, logger=logger)
2836+
def _load_results_metadata_from_file(metadata_file: Path):
2837+
with open(metadata_file) as f:
2838+
return json.load(f)
2839+
28332840
@staticmethod
28342841
def _load_results_metadata_from_uri(results_metadata_uri: Optional[str], job_id: str) -> Optional[dict]:
28352842
# TODO: reduce code duplication with load_results_metadata
@@ -2843,10 +2850,9 @@ def _load_results_metadata_from_uri(results_metadata_uri: Optional[str], job_id:
28432850
uri_parts = urlparse(results_metadata_uri)
28442851

28452852
if uri_parts.scheme == "file":
2846-
file_path = uri_parts.path
2853+
file_path = Path(uri_parts.path)
28472854
try:
2848-
with open(file_path) as f:
2849-
return json.load(f)
2855+
return GpsBatchJobs._load_results_metadata_from_file(file_path)
28502856
except FileNotFoundError:
28512857
logger.debug(
28522858
f"File with results metadata {file_path} does not exist; this is expected and not "

openeogeotrellis/job_registry.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import random
77
from datetime import datetime, timedelta
88
from decimal import Decimal
9+
from pathlib import Path
910
from typing import Any, List, Dict, Callable, Union, Optional, Iterator, Tuple
1011

1112
import kazoo
@@ -900,7 +901,7 @@ def _load_results_metadata_from_uri(results_metadata_uri: Optional[str], job_id:
900901
uri_parts = urlparse(results_metadata_uri)
901902

902903
if uri_parts.scheme == "file":
903-
file_path = uri_parts.path
904+
file_path = Path(uri_parts.path)
904905
try:
905906
with open(file_path) as f:
906907
return json.load(f)

0 commit comments

Comments
 (0)