Fix watcher status indicator — write status file every 5s, API reads it directly

This commit is contained in:
2026-04-25 16:58:19 +00:00
parent d765f9398b
commit 187d31eaff
2 changed files with 20 additions and 5 deletions
+12 -5
View File
@@ -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
+8
View File
@@ -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: