Cleanups for scrapers
This commit is contained in:
@@ -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:
|
||||
|
||||
Reference in New Issue
Block a user