fix(datastore): include morning-ending night sleep in dashboard, pass data-dir, and auto git-sync on writes
This commit is contained in:
@@ -295,9 +295,9 @@ class DatastoreEngine:
|
||||
import subprocess, shutil
|
||||
uv_bin = shutil.which("uv") or "/home/node/.openclaw/bin/uv"
|
||||
if Path(uv_bin).is_file():
|
||||
cmd = [str(uv_bin), "run", str(update_script)]
|
||||
cmd = [str(uv_bin), "run", str(update_script), "--data-dir", str(self.data_dir)]
|
||||
else:
|
||||
cmd = [sys.executable, str(update_script)]
|
||||
cmd = [sys.executable, str(update_script), "--data-dir", str(self.data_dir)]
|
||||
subprocess.Popen(
|
||||
cmd,
|
||||
stdout=subprocess.DEVNULL,
|
||||
@@ -306,6 +306,19 @@ class DatastoreEngine:
|
||||
except Exception as e:
|
||||
logger.warning(f"Could not trigger {script_name}: {e}")
|
||||
|
||||
def _git_sync(self, commit_msg: str):
|
||||
"""Safely commits and pushes data changes if data_dir is inside a git repository."""
|
||||
try:
|
||||
repo_dir = self.data_dir.parent if (self.data_dir.parent / ".git").is_dir() else self.data_dir
|
||||
if not (repo_dir / ".git").is_dir():
|
||||
return
|
||||
subprocess.run(["git", "-C", str(repo_dir), "add", str(self.data_dir)], check=False, capture_output=True)
|
||||
res = subprocess.run(["git", "-C", str(repo_dir), "commit", "-m", f"{commit_msg} [skip ci]"], check=False, capture_output=True)
|
||||
if res.returncode == 0:
|
||||
subprocess.run(["git", "-C", str(repo_dir), "push", "origin", "main"], check=False, capture_output=True, timeout=10)
|
||||
except Exception as e:
|
||||
logger.debug(f"Git auto-sync skipped/failed: {e}")
|
||||
|
||||
def _load_jsonl_file(self, file_path: Path, table_name: str):
|
||||
"""Reads lines from JSONL and inserts into target table."""
|
||||
if not file_path.is_file() or file_path.stat().st_size == 0:
|
||||
@@ -607,6 +620,7 @@ class DatastoreEngine:
|
||||
feedback["day_total_formatted"] = open_warning
|
||||
|
||||
self._trigger_website_update(subject)
|
||||
self._git_sync(f"chore(data): log {kind} for {subject}")
|
||||
|
||||
return {
|
||||
"status": "success",
|
||||
@@ -689,6 +703,7 @@ class DatastoreEngine:
|
||||
duration_minutes = int((end_dt.astimezone(BERLIN_TZ) - start_dt.astimezone(BERLIN_TZ)).total_seconds() / 60)
|
||||
|
||||
self._trigger_website_update(subject)
|
||||
self._git_sync(f"chore(data): stop {kind} for {subject}")
|
||||
|
||||
return {
|
||||
"status": "success",
|
||||
@@ -718,6 +733,7 @@ class DatastoreEngine:
|
||||
self._update_jsonl_record(domain, event_id, {"deleted_at": now_iso})
|
||||
|
||||
self._trigger_website_update(subject)
|
||||
self._git_sync(f"chore(data): delete event {event_id} ({kind}) for {subject}")
|
||||
|
||||
return {"status": "success", "deleted_event_id": event_id}
|
||||
|
||||
@@ -779,6 +795,8 @@ class DatastoreEngine:
|
||||
values,
|
||||
)
|
||||
|
||||
self._git_sync(f"chore(data): update entity {collection}/{entity_id}")
|
||||
|
||||
return {"status": "success", "collection": collection, "id": entity_id}
|
||||
|
||||
# --------------------------------------------------------------------------
|
||||
|
||||
Reference in New Issue
Block a user