Move alerting to Python#1931
Conversation
… into cam/schedule-batch-map
Reconcile scheduled batch maps with master's WMS cadence cron and API schedules; keep Python alert workers on prism_app.workers.alert_runner.
|
Visit the preview URL for this PR (updated for commit 7a985b5): https://staging-prism-frontend--1931-g7yvfz03.web.app (expires Sat, 18 Jul 2026 22:13:54 GMT) 🔥 via Firebase Hosting GitHub Action 🌎 Sign: 4de97634797dc19a4f4938b370446c2b3ddc1c37 |
Poetry lock was stale after alert worker deps landed, breaking all API CI jobs. Regenerate lock, fix isort on alert modules, bump pip floor to >=26.1.2 for pip-audit (CVE-2026-8643).
Add Cursor rule and prepare-commit-msg hook to strip Cursor trailers. Run ./scripts/install-githooks.sh once per clone.
b1141bf to
122bdbe
Compare
There was a problem hiding this comment.
Pull request overview
This PR is a WIP migration of the alerting system away from the Node-based alerting/ service into Python under the existing api/ package, while also adding a small frontend UX enhancement for copying batch map export settings.
Changes:
- Port threshold + anticipatory-action (storm/flood) alert workers to Python (
api/prism_app/alert_workers/*) and wire them into CI + cron scripts. - Remove the Node
alerting/service, its tests, and its dedicated GitHub Actions workflow. - Add a frontend “copy batch map settings” action that copies a readable
/exportURL to clipboard.
Reviewed changes
Copilot reviewed 110 out of 114 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| scripts/install-githooks.sh | Adds helper to point git hooks to .githooks/. |
| scripts/ec2-security-patch.sh | Stops updating yarn lockfiles for the removed alerting/ package. |
| frontend/src/components/NavBar/PrintImage/printConfig.tsx | Adds a copy-to-clipboard button for batch map settings. |
| frontend/src/components/NavBar/PrintImage/printConfig.context.ts | Exposes copyBatchMapUrls in the print config context. |
| frontend/src/components/NavBar/PrintImage/image.tsx | Implements copyBatchMapUrls and clipboard write behavior. |
| frontend/src/components/NavBar/PrintImage/batchExportUrls.ts | Adds helper to format export URLs for clipboard readability. |
| frontend/src/components/NavBar/PrintImage/batchExportUrls.test.ts | Unit test for clipboard URL formatting. |
| api/scripts/alert_email_ethereal_e2e_docker.sh | Adds Docker-driven E2E runner for Ethereal email previews. |
| api/requirements-export-map-worker.txt | Expands worker image requirements to support alert workers + templating. |
| api/README.md | Updates documentation to reflect Python alerting and new run paths. |
| api/pyproject.toml | Adds Python deps for the new alert worker stack (croniter, jinja2). |
| api/prism_app/workers/alert_runner.py | Adds CLI entrypoint to run threshold + AA workers and CI smoke. |
| api/prism_app/workers/init.py | Updates workers package docstring to include alert crons. |
| api/prism_app/tests/fixtures/moz_export.py | Adds helper for newline-separated schedule URL text fixtures. |
| api/prism_app/database/init.py | Exposes MapExportSchedule from the database package. |
| api/prism_app/ci/alert_db_smoke.py | Adds Python-based alerts DB smoke checks (SELECTs). |
| api/prism_app/ci/alert_db_contract.py | Adds Python-based alerts schema contract checks. |
| api/prism_app/ci/init.py | Adds CI helper package marker. |
| api/prism_app/alert_workers/init.py | Adds alert workers package marker. |
| api/prism_app/alert_workers/settings.py | Adds env/settings helpers for alert workers. |
| api/prism_app/alert_workers/db.py | Adds SQLAlchemy-based alerts DB access helpers. |
| api/prism_app/alert_workers/wcs_url.py | Adds WCS URL builders used by threshold worker. |
| api/prism_app/alert_workers/bbox_utils.py | Adds bbox helpers aligned with frontend/common behavior. |
| api/prism_app/alert_workers/layer_days.py | Adds WMS/WCS time-availability fetchers for alerts. |
| api/prism_app/alert_workers/mail_render.py | Adds Jinja2 rendering for storm/flood/threshold emails. |
| api/prism_app/alert_workers/smtp_mailer.py | Adds SMTP sender with Ethereal integration and CID images. |
| api/prism_app/alert_workers/browser_shot.py | Adds Playwright screenshot capture for AA email maps. |
| api/prism_app/alert_workers/coastal_districts.py | Ports coastal district list for storm alert filtering. |
| api/prism_app/alert_workers/threshold_worker.py | Ports threshold alert worker logic from Node to Python. |
| api/prism_app/alert_workers/aa_storm.py | Ports AA storm worker logic from Node to Python. |
| api/prism_app/alert_workers/aa_flood.py | Ports AA flood worker logic from Node to Python. |
| api/prism_app/alert_workers/templates/threshold_alert.txt.j2 | Adds threshold email text template (Jinja2). |
| api/prism_app/alert_workers/templates/threshold_alert.html.j2 | Adds threshold email HTML template (Jinja2). |
| api/prism_app/alert_workers/templates/storm_alert.txt.j2 | Adds storm email text template (Jinja2). |
| api/prism_app/alert_workers/templates/storm_alert.html.j2 | Adds storm email HTML template (Jinja2). |
| api/prism_app/alert_workers/templates/flood_alert.txt.j2 | Adds flood email text template (Jinja2). |
| api/prism_app/alert_workers/templates/flood_alert.html.j2 | Adds flood email HTML template (Jinja2). |
| api/prism_app/alert_workers/assets/mapIcon.png | Adds icon asset for AA emails. |
| api/prism_app/alert_workers/assets/arrowForwardIcon.png | Adds icon asset for AA/threshold emails. |
| api/poetry.lock | Locks added Python dependencies. |
| api/Makefile | Adds api-alert-email-e2e convenience target. |
| api/Dockerfile.export-map-worker | Bumps pip tooling version for worker image. |
| api/Dockerfile | Bumps pip tooling version for API image. |
| api/docker-compose.yml | Adds shm sizing and env wiring for alert worker execution; adds local alerts PostGIS service. |
| api/crons/_compose_run.sh | Adds shared compose runner for one-shot cron commands with logging. |
| api/crons/cron_scheduled_public_maps.sh | Refactors scheduled public maps cron to use _compose_run.sh. |
| api/crons/cron_alert_run.sh | Adds threshold alerts cron wrapper. |
| api/crons/cron_aa_storm_alert_run.sh | Adds AA storm cron wrapper. |
| api/crons/cron_aa_flood_alert_run.sh | Adds AA flood cron wrapper. |
| api/.gitignore | Ignores local alerts DB docker volume directory. |
| api/.env.example | Adds alert SMTP env placeholders. |
| .github/workflows/api.yml | Updates CI to run Python alert DB contract/smoke + adds unit test job for alert workers. |
| .github/workflows/alerting.yml | Removes Node alerting workflow. |
| .githooks/prepare-commit-msg | Adds hook to strip Cursor co-author trailers. |
| .dockerignore | Removes ignore patterns for deleted alerting/ paths. |
| .cursor/rules/git-commits-no-cursor.mdc | Adds Cursor rule doc for commit attribution. |
| alerting/tsconfig.json | Deletes Node alerting TS config (alerting migration). |
| alerting/src/utils/raster-utils.ts | Deletes Node alerting utility. |
| alerting/src/utils/jest.config.js | Deletes Node alerting Jest config. |
| alerting/src/utils/email.ts | Deletes Node SMTP/email sender implementation. |
| alerting/src/utils/email.test.ts | Deletes Node SMTP/email sender tests. |
| alerting/src/utils/date.ts | Deletes Node date helper. |
| alerting/src/utils/date.test.ts | Deletes Node date helper tests. |
| alerting/src/utils/capture-utils.ts | Deletes Node Puppeteer screenshot code. |
| alerting/src/utils/capture-utils.test.ts | Deletes Node screenshot tests. |
| alerting/src/utils/analysis-utils.ts | Deletes Node threshold analysis code. |
| alerting/src/types/storm-reports.ts | Deletes Node alerting types. |
| alerting/src/types/storm-email.ts | Deletes Node alerting types. |
| alerting/src/types/flood-email.ts | Deletes Node alerting types. |
| alerting/src/types/anticipatory-action-alerts.ts | Deletes Node alerting types. |
| alerting/src/types/alert.ts | Deletes Node alerting types. |
| alerting/src/templates/storm-alert.ejs | Deletes Node storm email templates (EJS). |
| alerting/src/templates/flood-alert.ejs | Deletes Node flood email templates (EJS). |
| alerting/src/images/index.ts | Deletes Node image helper. |
| alerting/src/db/row-mappers.ts | Deletes Node DB row mappers. |
| alerting/src/db/row-mappers.test.ts | Deletes Node DB row mappers tests. |
| alerting/src/db/pool.ts | Deletes Node Postgres pool management. |
| alerting/src/db/alert-queries.ts | Deletes Node threshold alert DB queries. |
| alerting/src/db/aa-queries.ts | Deletes Node AA DB queries. |
| alerting/src/constants.ts | Deletes Node API URL constants. |
| alerting/src/ci/smoke-alerts-db-pool.ts | Deletes Node DB smoke script. |
| alerting/src/ci/smoke-alerting-workers.ts | Deletes Node worker smoke script. |
| alerting/src/ci/check-alerts-db-contract.ts | Deletes Node schema contract script. |
| alerting/src/alert-worker.ts | Deletes Node threshold worker. |
| alerting/src/alert-worker.test.ts | Deletes Node threshold worker tests. |
| alerting/src/aa-storm-alert/worker.ts | Deletes Node AA storm worker. |
| alerting/src/aa-storm-alert/worker.test.ts | Deletes Node AA storm worker tests. |
| alerting/src/aa-storm-alert/test-utils.ts | Deletes Node AA storm test utils. |
| alerting/src/aa-storm-alert/districs.ts | Deletes Node AA storm districts list. |
| alerting/src/aa-storm-alert/alert.ts | Deletes Node AA storm logic module. |
| alerting/src/aa-storm-alert/alert.test.ts | Deletes Node AA storm tests. |
| alerting/src/aa-storm-alert/snapshots/alert.test.ts.snap | Deletes Node snapshot file. |
| alerting/src/aa-storm-alert-runner.ts | Deletes Node storm runner. |
| alerting/src/aa-flood-alert/worker.ts | Deletes Node AA flood worker. |
| alerting/src/aa-flood-alert/alert.ts | Deletes Node AA flood logic module. |
| alerting/src/aa-flood-alert-runner.ts | Deletes Node flood runner. |
| alerting/src/aa-common/runner.ts | Deletes Node shared AA runner. |
| alerting/src/aa-common/runner.test.ts | Deletes Node AA runner tests. |
| alerting/README.md | Deletes Node alerting README (moved to API docs). |
| alerting/package.json | Deletes Node alerting package manifest and scripts. |
| alerting/Dockerfile | Deletes Node alerting Dockerfile. |
| alerting/docker-compose.yml | Deletes Node alerting compose stack. |
| alerting/crons/cron_alert_run.sh | Deletes Node alert cron script. |
| alerting/crons/cron_aa_storm_alert_run.sh | Deletes Node storm cron script. |
| alerting/crons/cron_aa_flood_alert_run.sh | Deletes Node flood cron script. |
| alerting/.prettierrc | Deletes Node formatting config. |
| alerting/.gitignore | Deletes Node ignore file. |
| alerting/.eslintrc | Deletes Node eslint config. |
| alerting/.eslintignore | Deletes Node eslint ignore. |
| alerting/.env.example | Deletes Node alerting env example. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
|
@copilot fix failing linting and CI |
Fixed in |
Description
Removing node backend and move our alerting mechanisms to the frontend.
python -m prism_app.workers.alert_runner(threshold, aa-flood, aa-storm, smoke), api cronsmake api-alert-email-e2e)make send-test-email(Ethereal preview with --test-email / is_test bypass when trigger is not exceeded)How to test the feature:
cd api && make api,make db-seedmake send-test-email(flood email shown below, open Ethereal preview URL email in logs)make send-test-email WORKER=aa-storm(storm email shown below, open Ethereal preview URL email in logs)make api-alert-email-e2e(slow; flood/storm/threshold layout parity)Checklist - did you ...
Test your changes with
REACT_APP_COUNTRY=rbd yarn startREACT_APP_COUNTRY=cambodia yarn startREACT_APP_COUNTRY=mozambique yarn startPost-deploy checklist
crontab -eupdates on EC2 instancechmod +x api/crons/cron_*.sh api/crons/_compose_run.shalerting-nodecontainer if runningcd ~/prism-app/api source set_envs.sh docker compose run --rm --no-deps export_map_worker \ python -c "from prism_app.alert_workers.smtp_mailer import require_smtp_configured; require_smtp_configured(); print('SMTP OK')"aa-floodandaa-stormFuture considerations for improvement
last_triggeredorlast_statesgetting updated are not proof of mail sent successfullyScreenshot/video of feature:
Flood alert email (ethereal)

Storm alert email (ethereal)

Threshold alert email (ethereal)
