Cleanups for scrapers

This commit is contained in:
2026-04-10 10:04:20 -04:00
parent 0d5cc08bc0
commit 052a762182
15 changed files with 1411 additions and 567 deletions
+7 -3
View File
@@ -68,16 +68,20 @@ class ScraperStateManager:
return DEFAULT_STATE.copy()
def _save_state(self):
"""Save state to file"""
"""Save state to file using atomic write to prevent corruption"""
with self._lock:
try:
with open(STATE_FILE, 'w') as f:
tmp_file = STATE_FILE.with_suffix('.json.tmp')
with open(tmp_file, 'w') as f:
json.dump(self.state, f, indent=2, default=str)
os.replace(tmp_file, STATE_FILE)
except Exception as e:
print(f"Error saving scraper state: {e}")
def get_state(self) -> dict:
"""Get current state"""
"""Get current state, reloading from file to pick up changes from other processes"""
self.state = self._load_state()
# Check if monitor is still running
if self.state["monitor_pid"]:
try: