Guard arr cache writes against in-flight rescans, add rescan monitor tool

A direct arr_cache_write() call mid-rescan wrote a partial snapshot that
looked like real data loss to every consumer of the cache. The guard now
lives in arr_cache_write() itself so every caller is protected, not just
arr_get_tracked_data(). arr_rescan_monitor.sh closes the resulting gap for
rescans triggered outside arr_full_rescan.sh's own trigger-and-wait path.
This commit is contained in:
Gmer4Lfe
2026-07-16 22:57:54 -04:00
parent fb13958881
commit 2c3f0b9cb1
5 changed files with 215 additions and 2 deletions
+55
View File
@@ -22,6 +22,7 @@ making any changes.
- [arr_profile_enforcer.sh](#arr_profile_enforcersh)
- [webhook_setup.sh](#webhook_setupsh)
- [ramdisk_stop.sh](#ramdisk_stopsh)
- [arr_rescan_monitor.sh](#arr_rescan_monitorsh)
- [Adding a New Tool](#adding-a-new-tool)
---
@@ -733,6 +734,60 @@ ramdisk_stop.sh --log # verbose — show each step
---
## arr_rescan_monitor.sh
Waits for an already-active rescan-type command (RescanFolders/RescanSeries/RescanMovie,
DownloadedXScan, RefreshX) on the given arr to finish, then refreshes the shared tracked-data
cache (`arr_cache_write()` in common.sh) with the real post-scan numbers. Triggers nothing
itself — for watching a rescan that was already started some other way (manual API call,
the arr's own UI, an ad-hoc debugging session).
### When to Use
```
You manually trigger a RescanFolders/RescanSeries/RescanMovie outside arr_full_rescan.sh
→ arr_cache_write() correctly refuses to write while it's active (2026-07-17 — a mid-scan
write once read as real data loss to every consumer of the cache)
→ nothing writes the real number through once the scan finishes unless something is
watching for completion — that's this tool
arr_full_rescan.sh's weekly run finds one arr already mid-rescan and skips it
→ that arr's cache stays stale until its own rescan finishes; run this to close the gap
without waiting for next week's scheduled run
```
### What It Does NOT Do
Does not trigger a rescan — if none is active, it exits immediately with nothing to wait
for. Use the arr's own UI/API, or `Arrs_Stack/arr_full_rescan.sh`, to start one.
### Usage
```bash
# Wait for lidarr's active rescan (if any) to finish, then refresh its cache:
arr_rescan_monitor.sh lidarr
# Override the default 2-hour wait ceiling (seconds):
arr_rescan_monitor.sh lidarr 3600
# Check whether a rescan is active and the cache's current age, no waiting:
arr_rescan_monitor.sh lidarr --status
# Show what would be waited on without waiting or writing the cache:
arr_rescan_monitor.sh lidarr --dry-run
```
### Notes
- Safe to run against sonarr/radarr the same way — arr_type is the only required arg
- If the wait times out (default 7200s), the cache is left untouched — re-run once the scan
actually finishes, or let it pick up naturally next time something calls
`arr_get_tracked_data()` and finds the cache stale with no active rescan
- Does not conflict with `arr_full_rescan.sh` — that script already refreshes its own cache
on completion for scans it triggers itself; this covers everything it didn't start
---
## docker_prune_images.sh
Removes orphaned Docker images that accumulate after container updates. Two modes: