Repository navigation
feat(ingestion): orchestrate dbt Cloud Run Job from main.py (T9.17, D108) - #81
Merged
Merged
Conversation
Module-level frozenset listing the ingestion sources whose failure must prevent the downstream dbt Cloud Run Job invocation. Defined ahead of its first usage to make the orchestration whitelist reviewable in isolation (T9.17, D108).
Add fire-and-forget invocation of the datatalent-dbt Cloud Run Job at the end of main(), skipped iff a critical ingestion source failed. The RPC return is treated as acknowledgement only; downstream failures are surfaced by the Cloud Monitoring alert on datatalent-dbt (D105). Invocation runs before sys.exit(1) so that non-critical source failures (geo, urssaf_*, sirene, bmo) still trigger dbt while preserving the D19 partial-failure exit code. Refs: D72, D108, T9.17.
Add four unit tests for the dbt Cloud Run Job invocation logic (D108): - full success → dbt invoked with the projects/.../jobs/datatalent-dbt name - non-critical failure (geo) → dbt still invoked, sys.exit(1) preserved - critical failure (france_travail) → dbt skipped, sys.exit(1) preserved - run_job raising → main() logs but does not re-raise (fire-and-forget) Tests patch main.run_v2.JobsClient (where the symbol is looked up) and main.GCP_PROJECT_ID / main.GCP_REGION (module-level constants, captured at import time). No real Cloud Run API call. Refs: T9.17, D108.
This was referenced May 23, 2026
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.
Contexte
Cette PR met en œuvre T9.17 (US9, Orchestration prod ingestion → dbt) et finalise la chaîne d'orchestration actée en D72. Jusqu'ici, le Cloud Run Job `datatalent-dbt` était provisionné en Terraform (PR #52) et avait son CD branché (PR #54), mais aucun acteur ne le déclenchait. À partir de cette PR, `ingestion/main.py` invoque le Job dbt en fin de pipeline, conditionnellement à la réussite des sources critiques.
La décision D108 (rédigée dans `notes-projet.md` en pré-implémentation) acte les deux sous-arbitrages restants de T9.17 : comportement sur échec partiel, et mode d'invocation.
Décisions techniques
Justifications synthétiques :
Sémantique exit code (D19) préservée : exit 1 sur échec partiel d'ingestion, orthogonal à la décision d'invoquer dbt. L'invocation `invoke_dbt()` est placée avant `sys.exit(1)` pour garantir que les échecs non-critiques (geo, urssaf*) ne court-circuitent pas le déclenchement dbt.
Changements
Validation
```
$ uv run pytest -v tests/test_main.py
============================= test session starts ==============================
collected 6 items
tests/test_main.py::TestMain::test_calls_all_sources_in_order PASSED [ 16%]
tests/test_main.py::TestMain::test_continues_on_failure PASSED [ 33%]
tests/test_main.py::TestDbtInvocation::test_invokes_dbt_on_full_success PASSED [ 50%]
tests/test_main.py::TestDbtInvocation::test_invokes_dbt_on_non_critical_failure PASSED [ 66%]
tests/test_main.py::TestDbtInvocation::test_skips_dbt_on_critical_failure PASSED [ 83%]
tests/test_main.py::TestDbtInvocation::test_does_not_raise_when_run_job_fails PASSED [100%]
============================== 6 passed in 1.35s ===============================
```
```
$ uv run python -c "import main; print('import OK; CRITICAL_SOURCES=', main.CRITICAL_SOURCES)"
import OK; CRITICAL_SOURCES= frozenset({'france_travail', 'adzuna'})
```
Lint ruff + format : OK (validés à chaque commit via pre-commit).
Articulation avec D105
L'alerte Cloud Monitoring "échec exécution `datatalent-dbt`" (provisionnée par la prochaine PR `feat/monitoring-module`) devient le seul signal d'échec côté dbt. C'est précisément ce qui justifie le `try/except Exception` non-re-raise dans `_invoke_dbt` — la robustesse n'est pas redondante côté code applicatif, elle est déléguée au monitoring (defense in depth par couche, pas par duplication).
Suite
Décisions liées
Refs : T9.17.