Skip to content

Scheduled Sync with Cron

Run WCP syncs automatically on a fixed schedule without manual intervention.

Add an entry to your crontab:

Terminal window
crontab -e

Sync every 5 minutes:

Terminal window
*/5 * * * * curl -s -X POST http://localhost:8000/api/sync/run >> /var/log/wcp-cron.log 2>&1

Sync once per hour:

Terminal window
0 * * * * curl -s -X POST http://localhost:8000/api/sync/run >> /var/log/wcp-cron.log 2>&1

Create /etc/systemd/system/wcp-sync.service:

[Unit]
Description=WCP sync cycle
[Service]
Type=oneshot
ExecStart=/usr/bin/curl -s -X POST http://localhost:8000/api/sync/run

Create /etc/systemd/system/wcp-sync.timer:

[Unit]
Description=Run WCP sync every 5 minutes
[Timer]
OnBootSec=1min
OnUnitActiveSec=5min
[Install]
WantedBy=timers.target

Enable:

Terminal window
sudo systemctl daemon-reload
sudo systemctl enable --now wcp-sync.timer

Check the last sync result:

Terminal window
curl http://localhost:8000/api/sync/status

View recent logs:

Terminal window
curl "http://localhost:8000/api/logs?limit=20"

Check health:

Terminal window
curl http://localhost:8000/health

If the WCP server is down when cron fires, the curl will fail silently. Add basic alerting:

Terminal window
*/5 * * * * curl -sf -X POST http://localhost:8000/api/sync/run || echo "WCP sync failed at $(date)" >> /var/log/wcp-errors.log

Or monitor the health endpoint with an uptime checker (UptimeRobot, Hetrix, etc.).