Why Scheduled Sync?
Webhook events are not always guaranteed to be delivered. Scheduled synchronization provides:- Drift prevention: Catches manual changes that bypass webhook detection
- Reliability: Ensures settings are eventually consistent even if webhooks fail
- Periodic auditing: Regular checks that all repositories remain compliant
- Recovery: Automatically corrects any configuration drift over time
README.md:418-421
CRON Configuration
Scheduled sync is configured using theCRON environment variable with node-cron syntax.
Node-Cron Syntax
index.js:649-659 and README.md:511-523
Configuration Examples
How Scheduled Sync Works
When the cron schedule triggers, Safe Settings performs a full synchronization across all repositories in the organization..github/settings.yml (org-level).github/suborgs/*.yml (suborg-level).github/repos/*.yml (repo-level)index.js:660-664
Sync Installation Function
ThesyncInstallation function is the core of scheduled synchronization.
Source: index.js:226-248
Key Features
- Installation-aware: Works with GitHub App installations
- Context creation: Builds a context object similar to webhook events
- Full sync: Calls
syncAllSettings()to process all repositories - NOP mode support: Can run in dry-run mode for testing
Performance Considerations
Scheduled sync is designed to handle large organizations efficiently:Rate Limiting
- Probot automatically handles GitHub API rate limits and abuse limits
- Requests are throttled and retried automatically
- Consider using less frequent schedules for large organizations
README.md:311-316
Selective Loading
- Configs are only loaded when needed
- Uses GitHub’s Tree API for efficient file listing
- Caches file contents with ETags to minimize data transfer
lib/settings.js:838-891
Smart Comparison
- Compares desired state with current GitHub settings
- Only makes API calls when actual changes are detected
- Skips repositories that are already in compliance
README.md:318-417
Token Lifetime
GitHub App tokens expire after 1 hour. Scheduled sync operations must complete within this timeframe. For very large organizations, consider:
- Optimizing your configuration structure
- Using fewer repositories per sync
- Splitting into multiple installations
README.md:308-310
Monitoring Scheduled Syncs
Each scheduled sync creates a check run in the admin repository, allowing you to monitor:- Execution time: When the sync ran
- Success/failure: Whether all settings were applied successfully
- Errors: Detailed error messages for any failures
- Changes applied: Summary of modifications made
Scheduled Sync vs Webhook Events
| Aspect | Webhook Events | Scheduled Sync |
|---|---|---|
| Trigger | Immediate (on change) | Periodic (cron schedule) |
| Latency | Seconds | Minutes to hours |
| Reliability | Depends on webhook delivery | Guaranteed if app is running |
| API Usage | Minimal (only affected repos) | Higher (checks all repos) |
| Use Case | Real-time enforcement | Drift prevention & recovery |
| Scope | Specific repos/events | All repositories |
Best Practices
Choose appropriate schedule frequency
Choose appropriate schedule frequency
For most organizations:
- Small (< 50 repos): Every 15-30 minutes
- Medium (50-500 repos): Every 1-2 hours
- Large (> 500 repos): Every 4-24 hours
Test with dry-run mode first
Test with dry-run mode first
Before enabling scheduled sync in production:This validates configurations without making actual changes.
Monitor check runs regularly
Monitor check runs regularly
Scheduled syncs create check runs in the admin repository. Monitor these for:
- Recurring errors
- Performance degradation
- Unexpected changes
Combine with webhook events
Combine with webhook events
Use both approaches:
- Webhooks for immediate enforcement
- Scheduled sync as a safety net for missed events or drift
Configure logging appropriately
Configure logging appropriately
Set
LOG_LEVEL to balance visibility and log volume:Environment Variables
Related environment variables for scheduled sync:| Variable | Default | Description |
|---|---|---|
CRON | (not set) | Node-cron schedule expression |
LOG_LEVEL | (varies) | Logging verbosity (trace, debug, info, warn, error) |
ADMIN_REPO | admin | Repository containing configurations |
README.md:507-551
Disabling Scheduled Sync
To disable scheduled synchronization, simply remove or comment out theCRON environment variable:
.env
Example: Production Configuration
A typical production setup for a medium-sized organization:.env
- Runs sync 12 times per day
- Balances drift prevention with API usage
- Provides adequate logging for monitoring
- Uses a custom admin repository name