Scheduler, snapshots, diffs и retention.
Operational core Source Watch: как планировать проверки без stampede, хранить снимки и diffs без бесконечного роста, дедуплицировать повторные события, обрабатывать backoff/rate limits и безопасно распределять browser/Docling/Qwen jobs рядом с Qwen 30B на server2.
1. Scheduler model
{
"watch_id": "watch_...",
"schedule": {
"interval_seconds": 21600,
"jitter_seconds": 300,
"priority": "HIGH"
},
"next_due_at": "...",
"last_run_at": "...",
"last_success_at": "...",
"backoff_state": {...}
}
Due selection
eligible = ACTIVE watches AND next_due_at <= now AND not already RUNNING AND dependency health allows execution
Jitter
Jitter обязателен, чтобы 500 источников с одинаковым интервалом не стартовали одновременно после restart.
2. Priority model
| Priority | Example | Scheduler behavior |
|---|---|---|
| CRITICAL | security advisory / safety source | fastest allowed interval, reserved capacity |
| HIGH | official release/manual | normal-high frequency |
| MEDIUM | support docs/changelog | standard |
| LOW | blog/forum/reference | long interval, opportunistic |
Fairness
priority weighted but starvation prohibited LOW cannot be postponed forever because HIGH queue is continuously busy.
3. Retry / backoff
Retryable
timeout 5xx temporary DNS 429 connection reset browser crash
Usually not retryable immediately
401/403 auth failed 404/410 depending history invalid URL SSRF block content too large malformed configuration
Backoff
attempt 1 → +1m attempt 2 → +5m attempt 3 → +30m then follow source-specific degraded schedule 429: respect Retry-After when valid
Budget
max_attempts_per_run max_retry_time max_daily_failures circuit breaker threshold
4. Separate queues by cost
QUEUE_HTTP plain HTTP / JSON / feeds QUEUE_BROWSER Playwright / JS rendering QUEUE_DOCUMENT Docling / PDF parsing QUEUE_SEMANTIC Qwen diff classification QUEUE_ROUTING Dossier / Researcher / Curator events
Why
Один тяжёлый PDF или зависший browser не должен блокировать тысячи дешёвых HTTP checks.
Concurrency configuration
http_workers = many browser_workers = few document_workers = few qwen_workers = very limited routing_workers = moderate
5. Snapshot storage
Canonical SourceSnapshot
{
"snapshot_id": "...",
"watch_id": "...",
"source_id": "...",
"retrieved_at": "...",
"fetch_status": "OK",
"http_status": 200,
"raw_hash": "...",
"normalized_hash": "...",
"structured_hash": "...",
"content_ref": "...",
"structured_ref": "...",
"size_bytes": 12345,
"adapter": "urlwatch"
}
Storage split
Postgres: metadata hashes state relations Object storage/files: raw HTML PDF normalized text structured JSON large diffs
Compression
Normalized snapshots и diffs можно compress; hashes считаются до/после normalization по определённым policy rules.
6. Diff storage
Diff levels
L0: hash comparison L1: normalized text diff L2: structured diff sections/tables/fields L3: semantic summary only when required
Diff object
{
"diff_id": "...",
"old_snapshot_id": "...",
"new_snapshot_id": "...",
"diff_type": "TEXT|STRUCTURED|EVENT",
"engine": "urlwatch|changedetection|docling|github|rss",
"summary": "...",
"detail_ref": "...",
"changed_paths": [...],
"changed_blocks": [...],
"created_at": "..."
}
Do not store duplicated full bodies in every diff
Diff должен ссылаться на immutable snapshots.
7. Retention policy
Principle
not every fetch needs full raw content forever
Suggested tiers
RECENT: keep every snapshot MEDIUM: keep meaningful snapshots + periodic checkpoints LONG TERM: keep: first last every meaningful change critical/retraction/security snapshots periodic checkpoint
Never delete automatically
- snapshots tied to HIGH/CRITICAL ChangeEvent;
- snapshots referenced by Dossier evidence;
- snapshots linked to Curator stale-check;
- snapshots under investigation/legal hold.
Retention object
{
"keep_raw_days": 30,
"keep_all_snapshots_days": 14,
"checkpoint_days": 30,
"keep_meaningful_forever": true
}
8. Deduplication / idempotency
Snapshot dedup
same watch_id + same normalized_hash → no new semantic snapshot needed or lightweight NOT_MODIFIED record
Change dedup
dedup key = watch_id + old_normalized_hash + new_normalized_hash + policy_version
GitHub
X-GitHub-Delivery → external event dedup key
RSS
feed identity + item GUID + content hash
Rule
Duplicate delivery может обновить delivery metadata, но не создавать второй Dossier event.
9. Reconciliation
Why
Внешний watcher backend может потерять/изменить watch config, быть восстановлен из backup или вручную изменён.
Reconcile loop
canonical WatchTarget vs external adapter state compare: external ID exists? URI same? selectors same? paused state same? revision compatible? result: IN_SYNC DRIFTED MISSING_EXTERNAL ORPHAN_EXTERNAL
Repair
MISSING_EXTERNAL → recreate projection DRIFTED → apply canonical config ORPHAN_EXTERNAL → quarantine / manual review Never: adopt external state silently as canonical.
10. server2 resource strategy
Resource budget concept
Qwen 30B has priority. Source Watch must yield under load.
Adaptive throttling
if Qwen latency / system load high: reduce: browser concurrency Docling concurrency semantic classification concurrency keep: critical webhooks critical lightweight HTTP watches
Queue pressure states
NORMAL BUSY THROTTLED DEGRADED
Schedule drift metric
schedule_drift = actual_start - next_due_at
Для LOW/MEDIUM источников небольшой drift допустим; для CRITICAL контролируется отдельно.
11. Golden operational tests
| Test | Expected |
|---|---|
| 500 watches restart together | jitter prevents stampede |
| 429 with Retry-After | respect server delay |
| browser job hangs | timeout, HTTP queue unaffected |
| large PDF parse | document queue only |
| same content 100 checks | no 100 duplicate meaningful snapshots |
| duplicate GitHub delivery | one ChangeEvent |
| projection watch deleted externally | reconcile recreates |
| Qwen under heavy load | semantic queue throttles |
| critical source changed | retained despite normal cleanup |
| retention cleanup | referenced snapshots preserved |
12. Definition of Scheduler/Diff/Storage Done
[ ] central scheduler [ ] jitter [ ] priority/fairness [ ] retry/backoff [ ] 429 handling [ ] circuit breaker [ ] separate cost queues [ ] concurrency limits [ ] canonical snapshot metadata [ ] diff levels [ ] object storage split [ ] retention tiers [ ] protected snapshots [ ] snapshot dedup [ ] change idempotency [ ] GitHub/RSS dedup [ ] backend reconciliation [ ] adaptive server2 throttling [ ] schedule drift metric [ ] operational golden tests