Skip to content

Commit 630b443

Browse files
committed
Clean Digitraffic weathercam datastreams on bootstrap
1 parent e45f201 commit 630b443

1 file changed

Lines changed: 28 additions & 0 deletions

File tree

publishers/digitraffic_weathercam/bootstrap_digitraffic_weathercam.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
get_config, _auth_header,
1212
ensure_procedure, ensure_datastream, ensure_deployment,
1313
find_by_uid, clean_resource, add_bootstrap_args, print_summary,
14+
api_get, api_delete,
1415
)
1516

1617

@@ -174,6 +175,33 @@ def _deploy_camera(camera: dict, system_server_id: str, base_url: str) -> dict:
174175

175176

176177
def clean_all(base_url: str, auth: str, *, dry_run: bool, stats: dict):
178+
# Remove companion datastreams first so schema changes can be reapplied on bootstrap.
179+
seen_systems: set[str] = set()
180+
for camera in _load_cameras():
181+
system_uid = _system_uid(camera["roadWeatherStationId"])
182+
if system_uid in seen_systems:
183+
continue
184+
seen_systems.add(system_uid)
185+
sys_id = find_by_uid(base_url, auth, "systems", system_uid, no_cache=True)
186+
if not sys_id:
187+
continue
188+
ds_list = api_get(base_url, f"systems/{sys_id}/datastreams", auth) or {}
189+
for ds in ds_list.get("items", []):
190+
if ds.get("outputName") != DS_OUTPUT_NAME:
191+
continue
192+
ds_id = ds.get("id")
193+
if not ds_id:
194+
continue
195+
if dry_run:
196+
print(f" [DRY] Would delete datastreams/{ds_id} ({DS_OUTPUT_NAME}) on system {sys_id}")
197+
stats.setdefault("dry_deleted", 0)
198+
stats["dry_deleted"] += 1
199+
else:
200+
if api_delete(base_url, f"datastreams/{ds_id}", auth):
201+
print(f" DELETE datastreams/{ds_id} ({DS_OUTPUT_NAME}) on system {sys_id}")
202+
stats.setdefault("deleted", 0)
203+
stats["deleted"] += 1
204+
177205
for camera in _load_cameras():
178206
clean_resource(base_url, auth, "deployments", _deploy_uid(camera), dry_run=dry_run, stats=stats, cascade=True)
179207
clean_resource(base_url, auth, "deployments", DEPLOY_GROUP_UID, dry_run=dry_run, stats=stats, cascade=True)

0 commit comments

Comments
 (0)