SyncJob¶
The SyncJob class handles incremental updates to previously crawled sites.
Overview¶
SyncJob efficiently updates your knowledge base by:
- Checking sitemap for new/updated URLs
- Using conditional requests (ETags, Last-Modified)
- Comparing content hashes for changes
- Marking deleted pages as tombstones
Usage¶
Basic Sync¶
import asyncio
from ragcrawl.config import SyncConfig
from ragcrawl.core import SyncJob
config = SyncConfig(
site_id="site_abc123",
use_sitemap=True,
use_conditional_requests=True,
)
job = SyncJob(config)
result = asyncio.run(job.run())
# Check what changed
print(f"New pages: {result.stats.pages_new}")
print(f"Updated pages: {result.stats.pages_changed}")
print(f"Deleted pages: {result.stats.pages_deleted}")
print(f"Unchanged: {result.stats.pages_unchanged}")
Sync with Age Filter¶
Only sync pages that haven't been checked recently:
config = SyncConfig(
site_id="site_abc123",
max_age_hours=24, # Only pages not synced in 24 hours
)
job = SyncJob(config)
result = asyncio.run(job.run())
Sync with Page Limit¶
config = SyncConfig(
site_id="site_abc123",
max_pages=100, # Stop after 100 pages
)
job = SyncJob(config)
result = asyncio.run(job.run())
Sync Strategies¶
SyncJob uses multiple strategies in order of efficiency:
1. Sitemap¶
If available, the sitemap provides: - List of all current URLs - Last modification dates - Change frequency hints
2. Conditional Requests¶
Uses HTTP headers to avoid downloading unchanged content:
Supports:
- If-None-Match with ETags
- If-Modified-Since with Last-Modified dates
3. Content Hash Comparison¶
As a fallback, compares content hashes:
# This happens automatically when conditional requests
# don't indicate a change but content differs
Configuration¶
See SyncConfig for all options.
| Option | Type | Default | Description |
|---|---|---|---|
site_id |
str | required | Site to sync |
max_pages |
int | None | Maximum pages to sync |
max_age_hours |
float | None | Only sync pages older than N hours |
use_sitemap |
bool | True | Use sitemap for discovery |
use_conditional_requests |
bool | True | Use ETags/Last-Modified |
API Reference¶
SyncJob
¶
Incremental sync job for detecting content changes.
Uses multiple strategies: 1. Sitemap lastmod (if available) 2. HTTP conditional requests (ETag/Last-Modified) 3. Content hash diffing (fallback)
Initialize sync job.
| PARAMETER | DESCRIPTION |
|---|---|
config
|
Sync configuration.
TYPE:
|
Source code in src/ragcrawl/core/sync_job.py
run
async
¶
Execute the sync job.
| RETURNS | DESCRIPTION |
|---|---|
SyncResult
|
SyncResult with changed and deleted pages. |
Source code in src/ragcrawl/core/sync_job.py
| Python | |
|---|---|
92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 | |