Skip to content

Commit

Permalink
Add wait loop after write_assets(). Open-EO/openeo-geotrellis-extensi…
Browse files Browse the repository at this point in the history
  • Loading branch information
EmileSonneveld committed Oct 22, 2024
1 parent b0f48c4 commit a6b6eed
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
2 changes: 2 additions & 0 deletions openeogeotrellis/deploy/batch_job.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
add_permissions,
json_default,
to_jsonable,
wait_till_path_available,
)

logger = logging.getLogger('openeogeotrellis.deploy.batch_job')
Expand Down Expand Up @@ -354,6 +355,7 @@ def run_job(
ml_model_metadata = result.get_model_metadata(str(output_file))
logger.info("Extracted ml model metadata from %s" % output_file)
for name, asset in the_assets_metadata.items():
wait_till_path_available(Path(asset["href"]))
add_permissions(Path(asset["href"]), stat.S_IWGRP)
logger.info(f"wrote {len(the_assets_metadata)} assets to {output_file}")
assets_metadata.append(the_assets_metadata)
Expand Down
14 changes: 14 additions & 0 deletions openeogeotrellis/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import resource
import stat
import tempfile
import time
from functools import partial
from pathlib import Path
from typing import Callable, Iterable, Optional, Tuple, Union, Dict, Any, TypeVar
Expand Down Expand Up @@ -768,3 +769,16 @@ def to_jsonable(x):
return [to_jsonable(elem) for elem in x]

return x


def wait_till_path_available(path: Path):
retry = 0
max_tries = 5
while not os.path.exists(path):
if retry < max_tries:
retry += 1
time.sleep(10)
logger.info(f"Waiting for path to be available. Try {retry}/{max_tries}: {path}")
else:
logger.warning(f"Path is not available after {max_tries} tries: {path}")
return # TODO: Throw error instead

0 comments on commit a6b6eed

Please sign in to comment.