Files
news-platform/docs/AGGREGATOR_OPERATIONS.md
José Alves 3f7b4eff71
Tests / bridge tests (push) Failing after 7s
Tests / writer-pipeline tests (push) Successful in 31s
Tests / frontend lib tests (push) Successful in 31s
Tests / writer-pipeline tests (pull_request) Successful in 26s
Tests / bridge tests (pull_request) Successful in 27s
Tests / frontend lib tests (pull_request) Successful in 31s
feat(writer-pipeline): PT imprensa ingest for andebol.net (BIT-25559)
Add html_listing ingest for Record and A Bola andebol sections and
revista_imprensa PDF index parsing from FPA media. Document AGGREGATOR_URL
in bridge.env.example and AGGREGATOR_OPERATIONS.md.

Paperclip-Issue: BIT-25559
Paperclip-Run: 0ab092e1-68ab-4e5a-90bd-4262e9c3d9fc
2026-06-18 10:01:28 +00:00

74 lines
5.2 KiB
Markdown
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# Internal news aggregator — operations & costs (BIT-709)
This runbook covers the **self-hosted** multi-source aggregator in `writer-pipeline/` and how the **bridge** uses it for writer candidates.
## Components
| Piece | Role |
|--------|------|
| JSON store | `writer-pipeline/var/aggregated-items.json` (default path; override with `AGGREGATOR_STORE_PATH`) |
| Ingest config | `writer-pipeline/config/{site}.sources.json` (e.g. `andebol.net.sources.json`) |
| HTTP API | Fastify server (`npm run aggregator` → `dist/aggregator-server.js`) |
| Bridge integration | Set `AGGREGATOR_URL` (e.g. `http://127.0.0.1:3310`) so `/writers/:id/candidates` queries the aggregator **before** merging WordPress posts |
## HTTP API (aggregator process)
| Method | Path | Purpose |
|--------|------|---------|
| GET | `/health` | Liveness + resolved `storePath` |
| GET | `/search?site=&limit=&q=&topic=&max_age_hours=` | Searchable listing: tokenized `q` matches title+summary; deduped store keyed by canonical URL at ingest |
| GET | `/shortlist?site=&limit=&topic=` | Newest eligible items (no draft/skip) for one site |
| GET | `/stats` | Total items, counts by site and by `site:sourceFeedId` |
| POST | `/ingest?site=` | Run ingest for that site’s sources config and persist the store |
Environment:
- `AGGREGATOR_HOST` (default `127.0.0.1`), `AGGREGATOR_PORT` (default `3310`)
- `AGGREGATOR_CONFIG_DIR` — directory of `*.sources.json`
- `AGGREGATOR_STORE_PATH` — JSON backing file
## Bridge
- **`AGGREGATOR_URL`**: base URL of the aggregator (no trailing slash required). If unset, candidates come only from WordPress (previous behaviour).
- **`GET /writers/:agentId/candidates`**: loads aggregated items for `config.domain`, maps them to the same candidate shape as WordPress rows, adds **`source_url`** for external URLs, then merges WordPress posts and ranks. Response includes **`candidate_source`**: `aggregator` | `wordpress` | `mixed`.
- **`GET /writers/:agentId/stats`**: when the aggregator is enabled, also calls `GET /stats` and returns `aggregator_total_items` and `aggregator_site_items` when available.
## Data contract (per item)
Each aggregated item includes **source** (`sourceFeedId`, optional `sourceKind`), **timestamps** (`publishedAt`, `ingestedAt`), **technical summary** (`summary` + `title`), and **original URL** (`url`). Deduplication at ingest uses **canonical URL** → stable `id` (`store.itemId`).
## Sources, copyright, and wire services (Lusa)
- **Operational config:** `writer-pipeline/config/andebol.net.sources.json`. RSS feeds may set **`maxItems`** to limit how many recent entries are ingested per run (large highlight feeds such as SAPO).
- **PT imprensa (BIT-25559):** `html_listing` sources scrape handball-scoped sections (Record modalidades/andebol, A Bola /andebol). **`revista_imprensa`** parses FPA *Revista de Imprensa* PDFs from `portal.fpa.pt/media/` (Cision pressbook index) into story leads — titles + publisher labels, **without** republishing the PDF. ZeroZero listing is disabled when Cloudflare blocks the pipeline host.
- **Agência Lusa:** a direct, machine-readable **public Lusa wire feed suitable for unattended ingestion is not used here** — public endpoints are often HTML/portal pages or require a **commercial licence** and contractual terms. Syndicated PT feeds (e.g. SAPO highlights) may **credit Lusa or other agencies** in bylines; that does **not** replace checking rights for republication. Editors must follow `docs/ANDEBOL_EDITORIAL_BRIEF.md` (original rewrite, attribution, no verbatim copy).
- **Third-party RSS (Record, Guardian, BBC, etc.):** use only as **story leads**; comply with each site’s **terms of use** and robots/API policy; **English** items are for triage only — **andebol.net** publishes **European Portuguese (PT-PT)** only.
## Cost model (read-phase, LLM)
Structured read context for one item is built in `writer-pipeline/src/token-metrics.ts` (`aggregatorReadContext`). Reference **input** pricing used in metrics: **USD 0.15 / 1M tokens** (`REF_INPUT_USD_PER_1M`) — adjust when the production model changes.
Typical savings vs full-page fetch for the same shortlist are documented in `docs/WRITER_PIPELINE_ANDEBOL.md` (example ratio ~9× fewer tokens on the read path).
## Suggested scheduling (self-hosted)
1. **Ingest** — `POST /ingest?site=andebol.net` on a timer (e.g. every 6–12 hours per feed stability), or run `node dist/run-cycle.js` where you already use the pipeline.
2. **Aggregator process** — `systemd` or PM2 keeping `npm run aggregator` up on the same host (or container) as the bridge; bridge reaches it via loopback or private network.
3. **Bridge** — ensure `AGGREGATOR_URL` is set in the bridge environment alongside Redis/WordPress settings.
## Verification
```bash
cd writer-pipeline && npm run build && npm test
cd ../bridge && npm run build
# With aggregator running:
curl -sS "http://127.0.0.1:3310/search?site=andebol.net&limit=5"
```
## Related docs
- `docs/runbooks/NEWS_PLATFORM_INCIDENT_RUNBOOK_BIT3915.md` — incident response (stall, lag, escalation)
- `docs/AGGREGATOR_ARCHITECTURE.md` — long-term schema and phased plan
- `docs/WRITER_PIPELINE_ANDEBOL.md` — pipeline commands and metrics
- `docs/writer-tools.md` — bridge writer API