Spaces:
Running
Running
feat: reduce default workspace sync interval to 180s and refactor sync logic into a dedicated function
Browse files- .env.example +2 -2
- README.md +1 -1
- start.sh +2 -1
- workspace-sync.py +42 -35
.env.example
CHANGED
|
@@ -162,8 +162,8 @@ WORKSPACE_GIT_NAME=OpenClaw Bot
|
|
| 162 |
# Keep-alive ping interval (seconds). Default: 300. Set 0 to disable.
|
| 163 |
KEEP_ALIVE_INTERVAL=300
|
| 164 |
|
| 165 |
-
# Workspace auto-sync interval (seconds). Default:
|
| 166 |
-
SYNC_INTERVAL=
|
| 167 |
|
| 168 |
# Webhooks: Standard POST notifications for lifecycle events
|
| 169 |
# WEBHOOK_URL=https://your-webhook-endpoint.com/log
|
|
|
|
| 162 |
# Keep-alive ping interval (seconds). Default: 300. Set 0 to disable.
|
| 163 |
KEEP_ALIVE_INTERVAL=300
|
| 164 |
|
| 165 |
+
# Workspace auto-sync interval (seconds). Default: 180.
|
| 166 |
+
SYNC_INTERVAL=180
|
| 167 |
|
| 168 |
# Webhooks: Standard POST notifications for lifecycle events
|
| 169 |
# WEBHOOK_URL=https://your-webhook-endpoint.com/log
|
README.md
CHANGED
|
@@ -120,7 +120,7 @@ For persistent chat history and configuration, HuggingClaw can sync your workspa
|
|
| 120 |
| `HF_USERNAME` | β | Your HuggingFace username |
|
| 121 |
| `HF_TOKEN` | β | HF token with write access |
|
| 122 |
| `BACKUP_DATASET_NAME` | `huggingclaw-backup` | Dataset name for backup repo |
|
| 123 |
-
| `SYNC_INTERVAL` | `
|
| 124 |
| `WORKSPACE_GIT_USER` | `openclaw@example.com` | Git commit email for syncs |
|
| 125 |
| `WORKSPACE_GIT_NAME` | `OpenClaw Bot` | Git commit name for syncs |
|
| 126 |
|
|
|
|
| 120 |
| `HF_USERNAME` | β | Your HuggingFace username |
|
| 121 |
| `HF_TOKEN` | β | HF token with write access |
|
| 122 |
| `BACKUP_DATASET_NAME` | `huggingclaw-backup` | Dataset name for backup repo |
|
| 123 |
+
| `SYNC_INTERVAL` | `180` | Sync interval in seconds |
|
| 124 |
| `WORKSPACE_GIT_USER` | `openclaw@example.com` | Git commit email for syncs |
|
| 125 |
| `WORKSPACE_GIT_NAME` | `OpenClaw Bot` | Git commit name for syncs |
|
| 126 |
|
start.sh
CHANGED
|
@@ -9,6 +9,7 @@ set -e
|
|
| 9 |
OPENCLAW_VERSION="${OPENCLAW_VERSION:-latest}"
|
| 10 |
WHATSAPP_ENABLED="${WHATSAPP_ENABLED:-false}"
|
| 11 |
WHATSAPP_ENABLED_NORMALIZED=$(printf '%s' "$WHATSAPP_ENABLED" | tr '[:upper:]' '[:lower:]')
|
|
|
|
| 12 |
echo ""
|
| 13 |
echo " ββββββββββββββββββββββββββββββββββββββββββββ"
|
| 14 |
echo " β π¦ HuggingClaw Gateway β"
|
|
@@ -385,7 +386,7 @@ printf " β %-40s β\n" "Dashboard: https://${SPACE_HOST}"
|
|
| 385 |
fi
|
| 386 |
SYNC_STATUS="β disabled"
|
| 387 |
if [ -n "$HF_USERNAME" ] && [ -n "$HF_TOKEN" ]; then
|
| 388 |
-
SYNC_STATUS="β
every ${SYNC_INTERVAL:-
|
| 389 |
fi
|
| 390 |
printf " β %-40s β\n" "Auto-sync: $SYNC_STATUS"
|
| 391 |
if [ -n "$WEBHOOK_URL" ]; then
|
|
|
|
| 9 |
OPENCLAW_VERSION="${OPENCLAW_VERSION:-latest}"
|
| 10 |
WHATSAPP_ENABLED="${WHATSAPP_ENABLED:-false}"
|
| 11 |
WHATSAPP_ENABLED_NORMALIZED=$(printf '%s' "$WHATSAPP_ENABLED" | tr '[:upper:]' '[:lower:]')
|
| 12 |
+
SYNC_INTERVAL="${SYNC_INTERVAL:-180}"
|
| 13 |
echo ""
|
| 14 |
echo " ββββββββββββββββββββββββββββββββββββββββββββ"
|
| 15 |
echo " β π¦ HuggingClaw Gateway β"
|
|
|
|
| 386 |
fi
|
| 387 |
SYNC_STATUS="β disabled"
|
| 388 |
if [ -n "$HF_USERNAME" ] && [ -n "$HF_TOKEN" ]; then
|
| 389 |
+
SYNC_STATUS="β
every ${SYNC_INTERVAL:-180}s"
|
| 390 |
fi
|
| 391 |
printf " β %-40s β\n" "Auto-sync: $SYNC_STATUS"
|
| 392 |
if [ -n "$WEBHOOK_URL" ]; then
|
workspace-sync.py
CHANGED
|
@@ -28,7 +28,7 @@ EXCLUDED_STATE_NAMES = {
|
|
| 28 |
WHATSAPP_CREDS_DIR = Path("/home/node/.openclaw/credentials/whatsapp/default")
|
| 29 |
WHATSAPP_BACKUP_DIR = STATE_DIR / "credentials" / "whatsapp" / "default"
|
| 30 |
RESET_MARKER = WORKSPACE / ".reset_credentials"
|
| 31 |
-
INTERVAL = int(os.environ.get("SYNC_INTERVAL", "
|
| 32 |
INITIAL_DELAY = int(os.environ.get("SYNC_START_DELAY", "10"))
|
| 33 |
HF_TOKEN = os.environ.get("HF_TOKEN", "")
|
| 34 |
HF_USERNAME = os.environ.get("HF_USERNAME", "")
|
|
@@ -209,6 +209,44 @@ def sync_with_git():
|
|
| 209 |
return False
|
| 210 |
|
| 211 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 212 |
def main():
|
| 213 |
if "--snapshot-once" in sys.argv:
|
| 214 |
snapshot_state_into_workspace()
|
|
@@ -279,50 +317,19 @@ def main():
|
|
| 279 |
# Give the gateway a short head start before the first sync probe.
|
| 280 |
time.sleep(INITIAL_DELAY)
|
| 281 |
|
| 282 |
-
snapshot_state_into_workspace()
|
| 283 |
-
|
| 284 |
if use_hf_hub:
|
| 285 |
print(f"π Workspace sync started (huggingface_hub): every {INTERVAL}s β {HF_USERNAME}/{BACKUP_DATASET}")
|
| 286 |
else:
|
| 287 |
print(f"π Workspace sync started (git): every {INTERVAL}s")
|
| 288 |
|
|
|
|
|
|
|
| 289 |
while running:
|
| 290 |
time.sleep(INTERVAL)
|
| 291 |
if not running:
|
| 292 |
break
|
| 293 |
|
| 294 |
-
|
| 295 |
-
|
| 296 |
-
if not has_changes():
|
| 297 |
-
continue
|
| 298 |
-
|
| 299 |
-
ts = time.strftime("%Y-%m-%dT%H:%M:%SZ", time.gmtime())
|
| 300 |
-
|
| 301 |
-
write_sync_status("syncing", f"Starting sync at {ts}")
|
| 302 |
-
|
| 303 |
-
if use_hf_hub:
|
| 304 |
-
if sync_with_hf_hub():
|
| 305 |
-
print(f"π Workspace sync (hf_hub): pushed changes ({ts})")
|
| 306 |
-
write_sync_status("success", "Successfully pushed to HF Hub")
|
| 307 |
-
else:
|
| 308 |
-
# Fallback to git
|
| 309 |
-
if sync_with_git():
|
| 310 |
-
print(f"π Workspace sync (git fallback): pushed changes ({ts})")
|
| 311 |
-
write_sync_status("success", "Successfully pushed via git fallback")
|
| 312 |
-
else:
|
| 313 |
-
msg = f"Workspace sync: failed ({ts}), will retry"
|
| 314 |
-
print(f"π {msg}")
|
| 315 |
-
write_sync_status("error", msg)
|
| 316 |
-
trigger_webhook("sync", "error", msg)
|
| 317 |
-
else:
|
| 318 |
-
if sync_with_git():
|
| 319 |
-
print(f"π Workspace sync (git): pushed changes ({ts})")
|
| 320 |
-
write_sync_status("success", "Successfully pushed via git")
|
| 321 |
-
else:
|
| 322 |
-
msg = f"Workspace sync: push failed ({ts}), will retry"
|
| 323 |
-
print(f"π {msg}")
|
| 324 |
-
write_sync_status("error", msg)
|
| 325 |
-
trigger_webhook("sync", "error", msg)
|
| 326 |
|
| 327 |
|
| 328 |
if __name__ == "__main__":
|
|
|
|
| 28 |
WHATSAPP_CREDS_DIR = Path("/home/node/.openclaw/credentials/whatsapp/default")
|
| 29 |
WHATSAPP_BACKUP_DIR = STATE_DIR / "credentials" / "whatsapp" / "default"
|
| 30 |
RESET_MARKER = WORKSPACE / ".reset_credentials"
|
| 31 |
+
INTERVAL = int(os.environ.get("SYNC_INTERVAL", "180"))
|
| 32 |
INITIAL_DELAY = int(os.environ.get("SYNC_START_DELAY", "10"))
|
| 33 |
HF_TOKEN = os.environ.get("HF_TOKEN", "")
|
| 34 |
HF_USERNAME = os.environ.get("HF_USERNAME", "")
|
|
|
|
| 209 |
return False
|
| 210 |
|
| 211 |
|
| 212 |
+
def run_sync_pass(use_hf_hub: bool) -> None:
|
| 213 |
+
"""Snapshot state and push it if anything changed."""
|
| 214 |
+
snapshot_state_into_workspace()
|
| 215 |
+
|
| 216 |
+
if not has_changes():
|
| 217 |
+
return
|
| 218 |
+
|
| 219 |
+
ts = time.strftime("%Y-%m-%dT%H:%M:%SZ", time.gmtime())
|
| 220 |
+
write_sync_status("syncing", f"Starting sync at {ts}")
|
| 221 |
+
|
| 222 |
+
if use_hf_hub:
|
| 223 |
+
if sync_with_hf_hub():
|
| 224 |
+
print(f"π Workspace sync (hf_hub): pushed changes ({ts})")
|
| 225 |
+
write_sync_status("success", "Successfully pushed to HF Hub")
|
| 226 |
+
return
|
| 227 |
+
|
| 228 |
+
if sync_with_git():
|
| 229 |
+
print(f"π Workspace sync (git fallback): pushed changes ({ts})")
|
| 230 |
+
write_sync_status("success", "Successfully pushed via git fallback")
|
| 231 |
+
return
|
| 232 |
+
|
| 233 |
+
msg = f"Workspace sync: failed ({ts}), will retry"
|
| 234 |
+
print(f"π {msg}")
|
| 235 |
+
write_sync_status("error", msg)
|
| 236 |
+
trigger_webhook("sync", "error", msg)
|
| 237 |
+
return
|
| 238 |
+
|
| 239 |
+
if sync_with_git():
|
| 240 |
+
print(f"π Workspace sync (git): pushed changes ({ts})")
|
| 241 |
+
write_sync_status("success", "Successfully pushed via git")
|
| 242 |
+
return
|
| 243 |
+
|
| 244 |
+
msg = f"Workspace sync: push failed ({ts}), will retry"
|
| 245 |
+
print(f"π {msg}")
|
| 246 |
+
write_sync_status("error", msg)
|
| 247 |
+
trigger_webhook("sync", "error", msg)
|
| 248 |
+
|
| 249 |
+
|
| 250 |
def main():
|
| 251 |
if "--snapshot-once" in sys.argv:
|
| 252 |
snapshot_state_into_workspace()
|
|
|
|
| 317 |
# Give the gateway a short head start before the first sync probe.
|
| 318 |
time.sleep(INITIAL_DELAY)
|
| 319 |
|
|
|
|
|
|
|
| 320 |
if use_hf_hub:
|
| 321 |
print(f"π Workspace sync started (huggingface_hub): every {INTERVAL}s β {HF_USERNAME}/{BACKUP_DATASET}")
|
| 322 |
else:
|
| 323 |
print(f"π Workspace sync started (git): every {INTERVAL}s")
|
| 324 |
|
| 325 |
+
run_sync_pass(use_hf_hub)
|
| 326 |
+
|
| 327 |
while running:
|
| 328 |
time.sleep(INTERVAL)
|
| 329 |
if not running:
|
| 330 |
break
|
| 331 |
|
| 332 |
+
run_sync_pass(use_hf_hub)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 333 |
|
| 334 |
|
| 335 |
if __name__ == "__main__":
|