Skip to content

Commit

Permalink
Simplify startup when using remote inventory
Browse files Browse the repository at this point in the history
  • Loading branch information
sandorkertesz committed Dec 18, 2024
1 parent 6a44499 commit 9ad92ee
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 12 deletions.
23 changes: 13 additions & 10 deletions src/earthkit/regrid/db.py
Original file line number Diff line number Diff line change
Expand Up @@ -462,15 +462,18 @@ def find(
def find_entry(self, gridspec_in, gridspec_out, method):
method = self._method_alias(method)
entry = self.index.find(gridspec_in, gridspec_out, method)
if entry is None:
if not self._accessor.is_local() and not self._accessor.checked_remote():
LOG.info(
f"Matrix not found in DB for {gridspec_in=} {gridspec_out=} {method=}"
)
LOG.info("Try to fetch remote index file to check for updates")
self._accessor.reload()
self._load_index()
entry = self.index.find(gridspec_in, gridspec_out, method)
if (
entry is None
and not self._accessor.is_local()
and not self._accessor.checked_remote()
):
LOG.info(
f"Matrix not found in DB for {gridspec_in=} {gridspec_out=} {method=}"
)
LOG.info("Try to fetch remote index file to check for updates")
self._accessor.reload()
self._load_index()
entry = self.index.find(gridspec_in, gridspec_out, method)

return entry

Expand Down Expand Up @@ -548,7 +551,7 @@ def find(*args, matrix_source=None, **kwargs):
return db.find(*args, **kwargs)


def _clear_all():
def _reset():
global DB_LIST
global SYS_DB
SYS_DB = MatrixDb(SystemAccessor())
Expand Down
5 changes: 3 additions & 2 deletions tests/test_remote_index.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,14 @@
import pytest

from earthkit.regrid import interpolate
from earthkit.regrid.db import _clear_all
from earthkit.regrid.db import _reset


@pytest.mark.download
@pytest.mark.tmp_cache
def test_remote_index_handling():
_clear_all()
# we need to reset the db to ensure to simulate a fresh start
_reset()

from earthkit.regrid.db import SYS_DB

Expand Down

0 comments on commit 9ad92ee

Please sign in to comment.