Fix watcher status indicator — write status file every 5s, API reads it directly
This commit is contained in:
+12
-5
@@ -420,11 +420,12 @@ async def get_status():
|
|||||||
watcher_running = False
|
watcher_running = False
|
||||||
last_indexed = "Unknown"
|
last_indexed = "Unknown"
|
||||||
try:
|
try:
|
||||||
result = subprocess.run(
|
import time as _time, json as _json
|
||||||
["systemctl", "is-active", "aaronai-watcher"],
|
_sp = Path("/home/aaron/aaronai/watcher_status.json")
|
||||||
capture_output=True, text=True
|
if _sp.exists():
|
||||||
)
|
_s = _json.loads(_sp.read_text())
|
||||||
watcher_running = result.stdout.strip() == "active"
|
_age = _time.time() - _s.get("timestamp", 0)
|
||||||
|
watcher_running = _s.get("running", False) and _age < 30
|
||||||
except:
|
except:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
@@ -446,6 +447,12 @@ async def get_status():
|
|||||||
if state_path.exists():
|
if state_path.exists():
|
||||||
state = json.loads(state_path.read_text())
|
state = json.loads(state_path.read_text())
|
||||||
file_count = len(state)
|
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:
|
except:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|||||||
@@ -14,6 +14,7 @@ STATE_FILE = "/home/aaron/aaronai/watcher_state.json"
|
|||||||
|
|
||||||
SUPPORTED = {'.pdf', '.docx', '.pptx', '.txt', '.md'}
|
SUPPORTED = {'.pdf', '.docx', '.pptx', '.txt', '.md'}
|
||||||
DEBOUNCE_SECONDS = 120
|
DEBOUNCE_SECONDS = 120
|
||||||
|
STATUS_FILE = "/home/aaron/aaronai/watcher_status.json"
|
||||||
|
|
||||||
logging.basicConfig(
|
logging.basicConfig(
|
||||||
level=logging.INFO,
|
level=logging.INFO,
|
||||||
@@ -109,6 +110,13 @@ def main():
|
|||||||
|
|
||||||
try:
|
try:
|
||||||
while True:
|
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:
|
if handler.pending:
|
||||||
elapsed = time.time() - handler.last_event
|
elapsed = time.time() - handler.last_event
|
||||||
if elapsed >= DEBOUNCE_SECONDS:
|
if elapsed >= DEBOUNCE_SECONDS:
|
||||||
|
|||||||
Reference in New Issue
Block a user