Repository navigation
Conversation
The harvester (#2682) sends the same requests, with the headers of a conditional GET, and parses what it got later. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Ct7g9RdZP8G8Nbo8LKKFBH
A harvester lists its sources (synced into harvest_sources), fetches one with a conditional GET and stores what changed. harvest_tick, every minute in the scheduler once harvest.enabled, claims the due sources (FOR UPDATE SKIP LOCKED, a lease) and runs them in 4 threads, 2 by host. Each policy says when to come back: a season, publication windows, after a new publication the next window, a backoff after errors. The payloads are kept 30 days; /health tells the state of each harvester. The tables of the avalanche bulletins are created by the same migration (#2682). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Ct7g9RdZP8G8Nbo8LKKFBH
The BRA of each massif of Météo-France and the latest file of each EAWS service, in the languages of c2c it publishes, every 15 minutes in the publication windows, hourly else, from November to June. Each new publication is stored as CAAML, and the danger of each region of the day (ratings by elevation, problems, aspects) is kept forever. The publications superseded the same day are pruned after a week. store.py reads them back for the next endpoints (#2682). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Ct7g9RdZP8G8Nbo8LKKFBH
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Ct7g9RdZP8G8Nbo8LKKFBH
- the danger by region keeps all its bands; rating_low/high and the bound only with one elevation bound - region_keys (a region and the regions holding it, SLF by digit) with GIN indexes, for the bulletins and the danger of a region; the latest bulletins are of the last 3 days - ratings: by day, the highest rating of the region and its sub-regions, and each of them - a publication is superseded when all its regions are published again later the same day (SLF changes its ids and groups) - a publication changed at the same time is updated - indexes on the foreign keys; a payload is unique by source, a content seen again refreshes it - after a publication, an hourly poll until the window ends - store returns Stored(published, state), the state is kept - the sources are synced every 10 minutes, disabled when gone and deleted after 30 days - no worker waits for a busy host: 2 lanes by host - harvest.<name>.enabled, keep_payloads_days and requests_per_minute by harvester (Météo-France: 40, its key allows 50 a minute) - the health check counts the enabled sources of the known harvesters - no Météo-France sources without its key Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Ct7g9RdZP8G8Nbo8LKKFBH
…the danger
/latest reads the database first (Redis in front, its key changing with
each publication), else fetches the bulletins on demand as before: a
region not harvested, or the database failing, answers as today.
/regions/{region_id}/{YYYY-MM-DD} answers the bulletins of a day
(#2686), cached for good once the day is over, and
/regions/{region_id}/ratings the danger of the region and its
sub-regions day by day, the last 7 days by default.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Ct7g9RdZP8G8Nbo8LKKFBH
SLF gives the weather of each micro-region with its bulletins (customData.CH.weather: 13 of the 17 kB of a bulletin, the same in each language): temperature and snowfall limit by hour, wind and new snow by day, for the 2 days before and the forecast day. It goes to region_weather_hours and region_weather_periods, written once by publication, the latest winning, and is removed from the stored CAAML (the bulletin endpoints did not answer it from the database). weather.weather() reads it back for an endpoint to come. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Ct7g9RdZP8G8Nbo8LKKFBH
A monthly job removes the customData of the bulletins (all the services, at all levels) whose day is more than 18 months ago: the texts, ratings, problems, regions, times and ids are kept, and the danger by region is untouched. compacted_at marks the rows done, a partial index finds the others. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Ct7g9RdZP8G8Nbo8LKKFBH
- backend.json: the harvest tick of the scheduler, the avalanche services (Météo-France DPBRA, EAWS CAAML), the bulletin tables and the read path (Redis, then PostgreSQL, else on demand); a card on the harvest. backend.html and backend.png are not rendered again yet. - docs/harvest.md: scheduling and policy, state and health, payloads, storage, read path and caching, adding a harvester, operations. - Linked from docs/README.md and the code layout of the README. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Ct7g9RdZP8G8Nbo8LKKFBH
… storage - compaction keeps the texts (those of Météo-France are in its customData): only the paths of store.COMPACTED go (Météo-France weather, snow cover, new snow, history; SLF aggregation, danger evolution, weather), set-based, committed by batch - updated_at on the bulletins and the danger by region, in the keys of the cache: a correction at the same time shows on a day over too - the danger of a period is cached as the bulletins of a day - a weather correction at the same time is stored, the same values of the other languages are not rewritten - the on-demand answer has no SLF weather either, and a region holds its sub-regions as in the database (CH-4 holds CH-4231) - /latest answers the stored day while valid, else fetches on demand, with the database session ended first - an index on the days of the danger by region - a bad day or date is a 400 in the shape of the API, under its name - harvest.<name>.enabled in the .ini templates (empty: as harvest.enabled) Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Ct7g9RdZP8G8Nbo8LKKFBH
… switches Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Ct7g9RdZP8G8Nbo8LKKFBH
Not up to standards ⛔🔴 Issues
|
| Category | Results |
|---|---|
| Security | 2 medium |
🟢 Metrics 442 complexity · 2 duplication
Metric Results Complexity 442 Duplication 2
NEW Get contextual insights on your PRs based on Codacy's metrics, along with PR and Jira context, without leaving GitHub. Enable AI reviewer
TIP This summary will be updated as you push new changes.
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The avalanche bulletins are harvested in the background and stored, instead of being fetched when a user asks. A small, generic harvester framework does the fetching, for the weather stations, partner sites and webcams to come. Closes #2682, closes #2686; the outing part of #2685 is UI-only for now (see below). Tracking: c2corg/c2c_ui#5174.
The design was chosen from alternatives (scheduling: a cron per provider, this framework, or a task queue; data model: as in #2682, shared harvest tables, or whole files). Details are in
docs/harvest.md.Harvesting (
c2corg_api/harvest/)schedulercontainer runs oneharvest_tickevery minute. It claims the due sources (harvest_sources.next_run_at) withFOR UPDATE SKIP LOCKEDand fetches them in 4 threads, in lanes by host (at most 2 requests at once per service).Policy:/healthgets aharvestsection, which never fails the check.harvest.enabled, andharvest.<name>.enabledper harvester. Everything is off by default.requests_per_minute: Météo-France is held at 40 a minute, leaving room under its quota of 50 for the PDFs fetched on demand.Avalanche storage
avalanche_bulletinsregion_keys(a region and the regions holding it) with a GIN indexcustomDatais removed and the texts kept (store.COMPACTED)avalanche_bulletin_regionsbands, problems, aspectsregion_weather_hours/_periodsharvest_sources,harvest_payloadsMeasured on the dev DB: about 2.3 KB per stored SLF bulletin (4.6 KB with its weather), 3.3 KB per French one; about 0.4 GB a season.
Read path
GET /avalanche-bulletins/regions/{region_id}/latestreads Postgres, with Redis in front, while the stored day is still valid. Otherwise it fetches on demand as before (new region, harvest off, a service late). The answer has the same shape either way, and the existing snapshots pass unchanged.GET /avalanche-bulletins/regions/{region_id}/{YYYY-MM-DD}returns the bulletins of a day. A day that is over is cached for good, withimmutableheaders; its cache key includesupdated_at, so a later correction still shows.GET /avalanche-bulletins/regions/{region_id}/ratings?from=&to=returns the danger per day (7 days by default, 366 at most), including sub-regions (CH-4).Not in this PR
/outings/{id}/avalanche-bulletinswill come with the EAWS micro-regions (Avalanche bulletins: EAWS micro-regions and danger summary for the map #2684).docs/architecture/src/backend.jsonis updated, butbackend.htmlandbackend.pngare not re-rendered, because Archify isn't available in the session. Someone with Archify needs to run the finalize command fromdocs/README.mdbefore merging. Itsmeta.repository.revisionshould also be bumped after merge, so the source links to the new files work.METEOFRANCE_API_KEYmust reach the scheduler container. Then turn onharvest_enabled(c2corg/v6-docker-compose).Tests
make testin the dev container); ruff is clean./latest.Generated by Claude Code