Skip to content

Commit 5e1d62a

Browse files
committed
Fix stale publisher resource lookups
1 parent e0b05f2 commit 5e1d62a

11 files changed

Lines changed: 35 additions & 20 deletions

File tree

publishers/aviation_wx/aviation_wx_publisher.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -239,9 +239,10 @@ def _system_uid(self, icao_id: str) -> str:
239239

240240
def connect(self):
241241
"""Resolve system and datastream IDs for each station via REST API."""
242+
self._ds_ids.clear()
242243
for st in self.stations:
243244
uid = self._system_uid(st["icao_id"])
244-
sys_id = find_by_uid(self._base_url, self._auth, "systems", uid)
245+
sys_id = find_by_uid(self._base_url, self._auth, "systems", uid, no_cache=True)
245246
if not sys_id:
246247
print(f" [WARN] System '{uid}' not found — skipping {st['icao_id']}")
247248
continue

publishers/bootstrap_helpers.py

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -229,10 +229,15 @@ def fn():
229229
_uid_cache: dict[str, str] = {}
230230

231231

232-
def find_by_uid(base_url: str, auth: str, collection: str, uid: str) -> str | None:
232+
def _uid_cache_key(base_url: str, collection: str, uid: str) -> str:
233+
return f"{base_url.rstrip('/')}:{collection}:{uid}"
234+
235+
236+
def find_by_uid(base_url: str, auth: str, collection: str, uid: str,
237+
*, no_cache: bool = False) -> str | None:
233238
"""Find a resource by UID in a collection. Returns server ID or None."""
234-
cache_key = f"{collection}:{uid}"
235-
if cache_key in _uid_cache:
239+
cache_key = _uid_cache_key(base_url, collection, uid)
240+
if not no_cache and cache_key in _uid_cache:
236241
return _uid_cache[cache_key]
237242

238243
result = api_get(base_url, f"{collection}?uid={uid}&limit=1000", auth)
@@ -244,8 +249,9 @@ def find_by_uid(base_url: str, auth: str, collection: str, uid: str) -> str | No
244249
if props.get("uid") == uid:
245250
item_id = item.get("id") or props.get("id")
246251
if item_id:
247-
_uid_cache[cache_key] = str(item_id)
248-
return str(item_id)
252+
item_id = str(item_id)
253+
_uid_cache[cache_key] = item_id
254+
return item_id
249255
return None
250256

251257

@@ -516,7 +522,7 @@ def ensure_procedure(base_url: str, auth: str, uid: str, stub_body: dict,
516522
stats.setdefault("created", 0)
517523
stats["created"] += 1
518524
if new_id:
519-
_uid_cache[f"procedures:{uid}"] = new_id
525+
_uid_cache[_uid_cache_key(base_url, "procedures", uid)] = new_id
520526
return new_id
521527

522528

@@ -574,7 +580,7 @@ def ensure_system(base_url: str, auth: str, uid: str, stub_body: dict,
574580
stats.setdefault("created", 0)
575581
stats["created"] += 1
576582
if new_id:
577-
_uid_cache[f"systems:{uid}"] = new_id
583+
_uid_cache[_uid_cache_key(base_url, "systems", uid)] = new_id
578584
return new_id
579585

580586

@@ -690,7 +696,7 @@ def ensure_deployment(base_url: str, auth: str, uid: str, stub_body: dict,
690696
stats.setdefault("created", 0)
691697
stats["created"] += 1
692698
if new_id:
693-
_uid_cache[f"deployments:{uid}"] = new_id
699+
_uid_cache[_uid_cache_key(base_url, "deployments", uid)] = new_id
694700
return new_id
695701

696702

@@ -713,8 +719,7 @@ def clean_resource(base_url: str, auth: str, collection: str, uid: str,
713719
stats["deleted"] += 1
714720

715721
# Invalidate cache
716-
cache_key = f"{collection}:{uid}"
717-
_uid_cache.pop(cache_key, None)
722+
_uid_cache.pop(_uid_cache_key(base_url, collection, uid), None)
718723

719724

720725
# ═══════════════════════════════════════════════════════════════════════════

publishers/coops/coops_publisher.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -260,9 +260,10 @@ def _system_uid(self, station_id: str) -> str:
260260

261261
def connect(self):
262262
"""Resolve system and datastream IDs for each station via REST API."""
263+
self._ds_ids.clear()
263264
for st in self.stations:
264265
uid = self._system_uid(st["id"])
265-
sys_id = find_by_uid(self._base_url, self._auth, "systems", uid)
266+
sys_id = find_by_uid(self._base_url, self._auth, "systems", uid, no_cache=True)
266267
if not sys_id:
267268
print(f" [WARN] System '{uid}' not found — skipping {st['id']}")
268269
continue

publishers/iss/iss_publisher.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,8 @@ def connect(self):
234234
"""Connect to server. Uses REST mode when OSH_BASE_URL is set, SDK otherwise."""
235235
if self._rest_mode:
236236
from publishers.bootstrap_helpers import api_get, find_by_uid
237-
sys_id = find_by_uid(self._base_url, self._auth, "systems", self.system_uid)
237+
self._ds_id = None
238+
sys_id = find_by_uid(self._base_url, self._auth, "systems", self.system_uid, no_cache=True)
238239
if not sys_id:
239240
raise RuntimeError(f"System '{self.system_uid}' not found on server")
240241
ds_list = api_get(self._base_url, f"systems/{sys_id}/datastreams", self._auth)

publishers/ndbc/ndbc_buoycam_publisher.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,9 +170,10 @@ def _system_uid(self, station_id: str) -> str:
170170

171171
def connect(self):
172172
"""Resolve BuoyCAM datastream IDs for each camera-equipped station."""
173+
self._ds_ids.clear()
173174
for st in self.stations:
174175
uid = self._system_uid(st["id"])
175-
sys_id = find_by_uid(self._base_url, self._auth, "systems", uid)
176+
sys_id = find_by_uid(self._base_url, self._auth, "systems", uid, no_cache=True)
176177
if not sys_id:
177178
print(f" [WARN] System '{uid}' not found — skipping {st['id']}")
178179
continue

publishers/ndbc/ndbc_publisher.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -205,9 +205,10 @@ def _system_uid(self, station_id: str) -> str:
205205

206206
def connect(self):
207207
"""Resolve system and datastream IDs for each station via REST API."""
208+
self._ds_ids.clear()
208209
for st in self.stations:
209210
uid = self._system_uid(st["id"])
210-
sys_id = find_by_uid(self._base_url, self._auth, "systems", uid)
211+
sys_id = find_by_uid(self._base_url, self._auth, "systems", uid, no_cache=True)
211212
if not sys_id:
212213
print(f" [WARN] System '{uid}' not found — skipping {st['id']}")
213214
continue

publishers/nws/nws_publisher.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -176,9 +176,10 @@ def _system_uid(self, station_id: str) -> str:
176176

177177
def connect(self):
178178
"""Resolve system and datastream IDs for each station via REST API."""
179+
self._ds_ids.clear()
179180
for st in self.stations:
180181
uid = self._system_uid(st["id"])
181-
sys_id = find_by_uid(self._base_url, self._auth, "systems", uid)
182+
sys_id = find_by_uid(self._base_url, self._auth, "systems", uid, no_cache=True)
182183
if not sys_id:
183184
print(f" [WARN] System '{uid}' not found — skipping {st['id']}")
184185
continue

publishers/opensky/opensky_publisher.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,8 @@ def __init__(self):
222222

223223
def connect(self):
224224
"""Resolve system and datastream ID via REST API."""
225-
sys_id = find_by_uid(self._base_url, self._auth, "systems", SYSTEM_UID)
225+
self._ds_id = None
226+
sys_id = find_by_uid(self._base_url, self._auth, "systems", SYSTEM_UID, no_cache=True)
226227
if not sys_id:
227228
raise RuntimeError(f"System '{SYSTEM_UID}' not found on server")
228229

publishers/usgs_eq/usgs_eq_publisher.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,8 @@ def __init__(self):
210210

211211
def connect(self):
212212
"""Resolve system and datastream ID via REST API."""
213-
sys_id = find_by_uid(self._base_url, self._auth, "systems", SYSTEM_UID)
213+
self._ds_id = None
214+
sys_id = find_by_uid(self._base_url, self._auth, "systems", SYSTEM_UID, no_cache=True)
214215
if not sys_id:
215216
raise RuntimeError(f"System '{SYSTEM_UID}' not found on server")
216217

publishers/usgs_nims/usgs_nims_publisher.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -190,11 +190,12 @@ def _system_uid(self, nwis_id: str) -> str:
190190

191191
def connect(self):
192192
"""Resolve system and imagery datastream IDs for each camera via REST API."""
193+
self._ds_ids.clear()
193194
connected = 0
194195
for cam in self.cameras:
195196
nwis_id = cam["nwisId"]
196197
uid = self._system_uid(nwis_id)
197-
sys_id = find_by_uid(self._base_url, self._auth, "systems", uid)
198+
sys_id = find_by_uid(self._base_url, self._auth, "systems", uid, no_cache=True)
198199
if not sys_id:
199200
print(f" [WARN] System '{uid}' not found — skipping {nwis_id}")
200201
continue

0 commit comments

Comments
 (0)