Skip to content

Commit 3516c6e

Browse files
authored
Merge pull request #3440 from PolicyEngine/feat/report-output-run-stage-5
Stage 5: Dual-write live updates into run tables
2 parents 897ed95 + 0f58675 commit 3516c6e

12 files changed

Lines changed: 2297 additions & 230 deletions

changelog.d/3440.changed.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Dual-write live simulation and report create/update traffic into the new run tables, keep parent run pointers in sync, and harden report mutations to remain country-scoped and transactionally consistent.

policyengine_api/routes/report_output_routes.py

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,12 @@ def create_report_output(country_id: str) -> Response:
5454
)
5555

5656
if existing_report:
57+
existing_report = (
58+
report_output_service.ensure_report_output_dual_write_state(
59+
existing_report["id"],
60+
country_id=country_id,
61+
)
62+
)
5763
# Report already exists, return it with 200 status
5864
response_body = dict(
5965
status="ok",
@@ -104,7 +110,9 @@ def get_report_output(country_id: str, report_id: int) -> Response:
104110
"""
105111
print(f"Getting report output {report_id} for country {country_id}")
106112

107-
report_output: dict | None = report_output_service.get_report_output(report_id)
113+
report_output: dict | None = report_output_service.get_report_output(
114+
country_id, report_id
115+
)
108116

109117
if report_output is None:
110118
raise NotFound(f"Report #{report_id} not found.")
@@ -160,7 +168,9 @@ def update_report_output(country_id: str) -> Response:
160168

161169
try:
162170
# First check if the report output exists
163-
existing_report = report_output_service.get_stored_report_output(report_id)
171+
existing_report = report_output_service.get_stored_report_output(
172+
country_id, report_id
173+
)
164174
if existing_report is None:
165175
raise NotFound(f"Report #{report_id} not found.")
166176

@@ -178,7 +188,9 @@ def update_report_output(country_id: str) -> Response:
178188

179189
# Get the updated stored record so stale-runtime jobs do not appear to
180190
# complete the current runtime lineage in the PATCH response.
181-
updated_report = report_output_service.get_stored_report_output(report_id)
191+
updated_report = report_output_service.get_stored_report_output(
192+
country_id, report_id
193+
)
182194

183195
response_body = dict(
184196
status="ok",

policyengine_api/routes/simulation_routes.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44

55
from policyengine_api.services.simulation_service import SimulationService
66
from policyengine_api.utils.payload_validators import validate_country
7-
from policyengine_api.constants import COUNTRY_PACKAGE_VERSIONS
87

98
simulation_bp = Blueprint("simulation", __name__)
109
simulation_service = SimulationService()
@@ -57,6 +56,10 @@ def create_simulation(country_id: str) -> Response:
5756
)
5857

5958
if existing_simulation:
59+
existing_simulation = simulation_service.ensure_simulation_dual_write_state(
60+
existing_simulation["id"],
61+
country_id=country_id,
62+
)
6063
# Simulation already exists, return it with 200 status
6164
response_body = dict(
6265
status="ok",

0 commit comments

Comments
 (0)