Spaces:
Paused
Paused
feat: reduce default workspace sync interval to 180s and refactor sync logic into a dedicated function
Browse filesFiles changed (4)
- .env.example+2-2
- README.md+1-1
- start.sh+2-1
- workspace-sync.py+42-35
161 unmodified lines162163164165166167168169161 unmodified lines# Keep-alive ping interval (seconds). Default: 300. Set 0 to disable.KEEP_ALIVE_INTERVAL=300# Workspace auto-sync interval (seconds). Default: 600.SYNC_INTERVAL=600# Webhooks: Standard POST notifications for lifecycle events# WEBHOOK_URL=https://your-webhook-endpoint.com/log161 unmodified lines162163164165166167168169161 unmodified lines# Keep-alive ping interval (seconds). Default: 300. Set 0 to disable.KEEP_ALIVE_INTERVAL=300# Workspace auto-sync interval (seconds). Default: 180.SYNC_INTERVAL=180# Webhooks: Standard POST notifications for lifecycle events# WEBHOOK_URL=https://your-webhook-endpoint.com/log
119 unmodified lines120121122123124125126119 unmodified lines| `HF_USERNAME` | β | Your HuggingFace username || `HF_TOKEN` | β | HF token with write access || `BACKUP_DATASET_NAME` | `huggingclaw-backup` | Dataset name for backup repo || `SYNC_INTERVAL` | `600` | Sync interval in seconds || `WORKSPACE_GIT_USER` | `openclaw@example.com` | Git commit email for syncs || `WORKSPACE_GIT_NAME` | `OpenClaw Bot` | Git commit name for syncs |119 unmodified lines120121122123124125126119 unmodified lines| `HF_USERNAME` | β | Your HuggingFace username || `HF_TOKEN` | β | HF token with write access || `BACKUP_DATASET_NAME` | `huggingclaw-backup` | Dataset name for backup repo || `SYNC_INTERVAL` | `180` | Sync interval in seconds || `WORKSPACE_GIT_USER` | `openclaw@example.com` | Git commit email for syncs || `WORKSPACE_GIT_NAME` | `OpenClaw Bot` | Git commit name for syncs |
8 unmodified lines91011121314370 unmodified lines3853863873883893903918 unmodified linesOPENCLAW_VERSION="${OPENCLAW_VERSION:-latest}"WHATSAPP_ENABLED="${WHATSAPP_ENABLED:-false}"WHATSAPP_ENABLED_NORMALIZED=$(printf '%s' "$WHATSAPP_ENABLED" | tr '[:upper:]' '[:lower:]')echo ""echo " ββββββββββββββββββββββββββββββββββββββββββββ"echo " β π¦ HuggingClaw Gateway β"370 unmodified linesfiSYNC_STATUS="β disabled"if [ -n "$HF_USERNAME" ] && [ -n "$HF_TOKEN" ]; thenSYNC_STATUS="β every ${SYNC_INTERVAL:-600}s"fiprintf " β %-40s β\n" "Auto-sync: $SYNC_STATUS"if [ -n "$WEBHOOK_URL" ]; then8 unmodified lines9101112131415370 unmodified lines3863873883893903913928 unmodified linesOPENCLAW_VERSION="${OPENCLAW_VERSION:-latest}"WHATSAPP_ENABLED="${WHATSAPP_ENABLED:-false}"WHATSAPP_ENABLED_NORMALIZED=$(printf '%s' "$WHATSAPP_ENABLED" | tr '[:upper:]' '[:lower:]')SYNC_INTERVAL="${SYNC_INTERVAL:-180}"echo ""echo " ββββββββββββββββββββββββββββββββββββββββββββ"echo " β π¦ HuggingClaw Gateway β"370 unmodified linesfiSYNC_STATUS="β disabled"if [ -n "$HF_USERNAME" ] && [ -n "$HF_TOKEN" ]; thenSYNC_STATUS="β every ${SYNC_INTERVAL:-180}s"fiprintf " β %-40s β\n" "Auto-sync: $SYNC_STATUS"if [ -n "$WEBHOOK_URL" ]; then
27 unmodified lines28293031323334174 unmodified lines20921021121221321464 unmodified lines27928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732827 unmodified linesWHATSAPP_CREDS_DIR = Path("/home/node/.openclaw/credentials/whatsapp/default")WHATSAPP_BACKUP_DIR = STATE_DIR / "credentials" / "whatsapp" / "default"RESET_MARKER = WORKSPACE / ".reset_credentials"INTERVAL = int(os.environ.get("SYNC_INTERVAL", "600"))INITIAL_DELAY = int(os.environ.get("SYNC_START_DELAY", "10"))HF_TOKEN = os.environ.get("HF_TOKEN", "")HF_USERNAME = os.environ.get("HF_USERNAME", "")174 unmodified linesreturn Falsedef main():if "--snapshot-once" in sys.argv:snapshot_state_into_workspace()64 unmodified lines# Give the gateway a short head start before the first sync probe.time.sleep(INITIAL_DELAY)snapshot_state_into_workspace()if use_hf_hub:print(f"π Workspace sync started (huggingface_hub): every {INTERVAL}s β {HF_USERNAME}/{BACKUP_DATASET}")else:print(f"π Workspace sync started (git): every {INTERVAL}s")while running:time.sleep(INTERVAL)if not running:breaksnapshot_state_into_workspace()if not has_changes():continuets = time.strftime("%Y-%m-%dT%H:%M:%SZ", time.gmtime())write_sync_status("syncing", f"Starting sync at {ts}")if use_hf_hub:if sync_with_hf_hub():print(f"π Workspace sync (hf_hub): pushed changes ({ts})")write_sync_status("success", "Successfully pushed to HF Hub")else:# Fallback to gitif sync_with_git():print(f"π Workspace sync (git fallback): pushed changes ({ts})")write_sync_status("success", "Successfully pushed via git fallback")else:msg = f"Workspace sync: failed ({ts}), will retry"print(f"π {msg}")write_sync_status("error", msg)trigger_webhook("sync", "error", msg)else:if sync_with_git():print(f"π Workspace sync (git): pushed changes ({ts})")write_sync_status("success", "Successfully pushed via git")else:msg = f"Workspace sync: push failed ({ts}), will retry"print(f"π {msg}")write_sync_status("error", msg)trigger_webhook("sync", "error", msg)if __name__ == "__main__":27 unmodified lines28293031323334174 unmodified lines20921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125264 unmodified lines31731831932032132232332432532632732832933033133233333433527 unmodified linesWHATSAPP_CREDS_DIR = Path("/home/node/.openclaw/credentials/whatsapp/default")WHATSAPP_BACKUP_DIR = STATE_DIR / "credentials" / "whatsapp" / "default"RESET_MARKER = WORKSPACE / ".reset_credentials"INTERVAL = int(os.environ.get("SYNC_INTERVAL", "180"))INITIAL_DELAY = int(os.environ.get("SYNC_START_DELAY", "10"))HF_TOKEN = os.environ.get("HF_TOKEN", "")HF_USERNAME = os.environ.get("HF_USERNAME", "")174 unmodified linesreturn Falsedef run_sync_pass(use_hf_hub: bool) -> None:"""Snapshot state and push it if anything changed."""snapshot_state_into_workspace()if not has_changes():returnts = time.strftime("%Y-%m-%dT%H:%M:%SZ", time.gmtime())write_sync_status("syncing", f"Starting sync at {ts}")if use_hf_hub:if sync_with_hf_hub():print(f"π Workspace sync (hf_hub): pushed changes ({ts})")write_sync_status("success", "Successfully pushed to HF Hub")returnif sync_with_git():print(f"π Workspace sync (git fallback): pushed changes ({ts})")write_sync_status("success", "Successfully pushed via git fallback")returnmsg = f"Workspace sync: failed ({ts}), will retry"print(f"π {msg}")write_sync_status("error", msg)trigger_webhook("sync", "error", msg)returnif sync_with_git():print(f"π Workspace sync (git): pushed changes ({ts})")write_sync_status("success", "Successfully pushed via git")returnmsg = f"Workspace sync: push failed ({ts}), will retry"print(f"π {msg}")write_sync_status("error", msg)trigger_webhook("sync", "error", msg)def main():if "--snapshot-once" in sys.argv:snapshot_state_into_workspace()64 unmodified lines# Give the gateway a short head start before the first sync probe.time.sleep(INITIAL_DELAY)if use_hf_hub:print(f"π Workspace sync started (huggingface_hub): every {INTERVAL}s β {HF_USERNAME}/{BACKUP_DATASET}")else:print(f"π Workspace sync started (git): every {INTERVAL}s")run_sync_pass(use_hf_hub)while running:time.sleep(INTERVAL)if not running:breakrun_sync_pass(use_hf_hub)if __name__ == "__main__":
.env.example+2-2
README.md+1-1
start.sh+2-1
workspace-sync.py+42-35