From 187d31eaff4251ac26271b42efdd5d91d51f98aa Mon Sep 17 00:00:00 2001 From: Aaron Nelson Date: Sat, 25 Apr 2026 16:58:19 +0000 Subject: [PATCH] =?UTF-8?q?Fix=20watcher=20status=20indicator=20=E2=80=94?= =?UTF-8?q?=20write=20status=20file=20every=205s,=20API=20reads=20it=20dir?= =?UTF-8?q?ectly?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- scripts/api.py | 17 ++++++++++++----- scripts/watcher.py | 8 ++++++++ 2 files changed, 20 insertions(+), 5 deletions(-) diff --git a/scripts/api.py b/scripts/api.py index 9af2251..a903fc4 100644 --- a/scripts/api.py +++ b/scripts/api.py @@ -420,11 +420,12 @@ async def get_status(): watcher_running = False last_indexed = "Unknown" try: - result = subprocess.run( - ["systemctl", "is-active", "aaronai-watcher"], - capture_output=True, text=True - ) - watcher_running = result.stdout.strip() == "active" + import time as _time, json as _json + _sp = Path("/home/aaron/aaronai/watcher_status.json") + if _sp.exists(): + _s = _json.loads(_sp.read_text()) + _age = _time.time() - _s.get("timestamp", 0) + watcher_running = _s.get("running", False) and _age < 30 except: pass @@ -446,6 +447,12 @@ async def get_status(): if state_path.exists(): state = json.loads(state_path.read_text()) file_count = len(state) + else: + # Count files in Nextcloud directly + nc_path = Path(NEXTCLOUD_PATH) + if nc_path.exists(): + file_count = sum(1 for f in nc_path.rglob("*") + if f.is_file() and f.suffix.lower() in {'.pdf','.docx','.pptx','.txt','.md'}) except: pass diff --git a/scripts/watcher.py b/scripts/watcher.py index 7a5afd2..4121b2b 100644 --- a/scripts/watcher.py +++ b/scripts/watcher.py @@ -14,6 +14,7 @@ STATE_FILE = "/home/aaron/aaronai/watcher_state.json" SUPPORTED = {'.pdf', '.docx', '.pptx', '.txt', '.md'} DEBOUNCE_SECONDS = 120 +STATUS_FILE = "/home/aaron/aaronai/watcher_status.json" logging.basicConfig( level=logging.INFO, @@ -109,6 +110,13 @@ def main(): try: while True: + import json as _json + _json.dump({ + "running": True, + "timestamp": time.time(), + "pending": handler.pending, + "last_event": handler.last_event + }, open(STATUS_FILE, 'w')) if handler.pending: elapsed = time.time() - handler.last_event if elapsed >= DEBOUNCE_SECONDS: