-
Notifications
You must be signed in to change notification settings - Fork 0
Split configured cycle summary and history helpers #649
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
ktalpay
merged 1 commit into
develop
from
codex/extract-cycle-summary-and-history-helpers
Jun 2, 2026
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
87 changes: 87 additions & 0 deletions
87
src/carbonfactor_parser/pipeline/configured_cycle_history.py
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,87 @@ | ||
| """Configured ingestion cycle run-history persistence helpers.""" | ||
|
|
||
| from __future__ import annotations | ||
|
|
||
| from datetime import datetime | ||
| from typing import Callable | ||
|
|
||
| from carbonfactor_parser.diagnostics.redaction import redact_sensitive_text | ||
| from carbonfactor_parser.persistence.ingestion_run_history import ( | ||
| ParserIngestionRunHistoryRepository, | ||
| ParserIngestionRunHistoryStatus, | ||
| ) | ||
| from carbonfactor_parser.persistence.ingestion_run_history_mapping import ( | ||
| build_ingestion_run_history_command_from_configured_cycle, | ||
| ) | ||
| from carbonfactor_parser.pipeline.configured_cycle_models import ConfiguredCycleResult | ||
|
|
||
|
|
||
| def persist_configured_cycle_history( | ||
| cycle: ConfiguredCycleResult, | ||
| *, | ||
| history_repository: ParserIngestionRunHistoryRepository, | ||
| started_at: datetime, | ||
| finished_at: datetime, | ||
| emit: Callable[[str], None] | None, | ||
| ) -> ConfiguredCycleResult: | ||
| """Persist run-history for a configured cycle without affecting ingestion result.""" | ||
|
|
||
| command = build_ingestion_run_history_command_from_configured_cycle( | ||
| cycle, | ||
| started_at=started_at, | ||
| finished_at=finished_at, | ||
| ) | ||
| try: | ||
| persist_result = history_repository.persist_ingestion_run_history(command) | ||
| except Exception as exc: # pragma: no cover - defensive boundary protection | ||
| safe_message = redact_sensitive_text(str(exc)) | ||
| if emit is not None: | ||
| emit( | ||
| "history_persistence " | ||
| f"status=failed run_id={cycle.run_id} " | ||
| "issue code=INGESTION_RUN_HISTORY_PERSISTENCE_EXCEPTION " | ||
| f"message={safe_message}" | ||
| ) | ||
| return ConfiguredCycleResult( | ||
| cycle_number=cycle.cycle_number, | ||
| run_id=cycle.run_id, | ||
| result=cycle.result, | ||
| history_persistence_status="failed", | ||
| history_persistence_issue_count=1, | ||
| ) | ||
|
|
||
| issue_count = len(persist_result.issues) | ||
| if persist_result.status is ParserIngestionRunHistoryStatus.DECLARED: | ||
| if emit is not None: | ||
| emit(f"history_persistence status=declared run_id={cycle.run_id}") | ||
| else: | ||
| if emit is not None: | ||
| for issue in persist_result.issues or (): | ||
| safe_message = redact_sensitive_text(str(issue.message)) | ||
| emit( | ||
| "history_persistence " | ||
| f"status=failed run_id={cycle.run_id} " | ||
| f"issue code={issue.code} message={safe_message}" | ||
| ) | ||
| if not persist_result.issues: | ||
| emit( | ||
| "history_persistence " | ||
| f"status=failed run_id={cycle.run_id} " | ||
| "issue code=INGESTION_RUN_HISTORY_PERSISTENCE_FAILED " | ||
| "message=run history persistence failed" | ||
| ) | ||
| issue_count = 1 | ||
| return ConfiguredCycleResult( | ||
| cycle_number=cycle.cycle_number, | ||
| run_id=cycle.run_id, | ||
| result=cycle.result, | ||
| history_persistence_status=( | ||
| "declared" | ||
| if persist_result.status is ParserIngestionRunHistoryStatus.DECLARED | ||
| else "failed" | ||
| ), | ||
| history_persistence_issue_count=issue_count, | ||
| ) | ||
|
|
||
|
|
||
| __all__ = ("persist_configured_cycle_history",) |
36 changes: 36 additions & 0 deletions
36
src/carbonfactor_parser/pipeline/configured_cycle_models.py
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,36 @@ | ||
| """Configured ingestion cycle result models.""" | ||
|
|
||
| from __future__ import annotations | ||
|
|
||
| from dataclasses import dataclass | ||
| from typing import TYPE_CHECKING | ||
|
|
||
| from carbonfactor_parser.pipeline.production_e2e_year_orchestrator import ( | ||
| ProductionE2EYearOrchestratorResult, | ||
| ) | ||
|
|
||
| if TYPE_CHECKING: | ||
| from carbonfactor_parser.pipeline.configured_cycle_runner import ( | ||
| ConfiguredCycleRunnerStatus, | ||
| ) | ||
|
|
||
|
|
||
| @dataclass(frozen=True) | ||
| class ConfiguredCycleResult: | ||
| """One completed application cycle.""" | ||
|
|
||
| cycle_number: int | ||
| run_id: str | ||
| result: ProductionE2EYearOrchestratorResult | ||
| history_persistence_status: str | None = None | ||
| history_persistence_issue_count: int = 0 | ||
|
|
||
|
|
||
| @dataclass(frozen=True) | ||
| class ConfiguredCycleRunnerResult: | ||
| """All cycles run by one application invocation.""" | ||
|
|
||
| status: ConfiguredCycleRunnerStatus | ||
| cycles: tuple[ConfiguredCycleResult, ...] | ||
| schema_created_table_names: tuple[str, ...] | ||
| schema_missing_table_names: tuple[str, ...] | ||
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
Oops, something went wrong.
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When
ConfiguredCycleRunnerResultis imported from the new models module, thestatusannotation is stored as the stringConfiguredCycleRunnerStatus, but that name only exists underTYPE_CHECKING. Runtime consumers that introspect this public result model withtyping.get_type_hints(ConfiguredCycleRunnerResult)now getNameError: name 'ConfiguredCycleRunnerStatus' is not defined; this worked before because the enum and dataclass lived in the same module. This affects serializers/schema builders or other API tooling that resolves annotations, so the enum should be moved/re-exported into a runtime-resolvable namespace instead of being only type-checking imported.Useful? React with 👍 / 👎.