-
Notifications
You must be signed in to change notification settings - Fork 1
separate application execution boundaries #17
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
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
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
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
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
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,53 @@ | ||
| """Local adapters for application runtime ports.""" | ||
|
|
||
| from __future__ import annotations | ||
|
|
||
| import os | ||
|
|
||
| from loafer.contracts import Checkpoint, RunEvent | ||
|
|
||
|
|
||
| class NeverCancelled: | ||
| """Default cancellation adapter for synchronous local execution.""" | ||
|
|
||
| def is_cancelled(self, run_id: str) -> bool: | ||
| del run_id | ||
| return False | ||
|
|
||
|
|
||
| class NullCheckpointStore: | ||
| """No-op checkpoint adapter until Phase 3 adds durable metadata.""" | ||
|
|
||
| def load(self, run_id: str, partition_id: str) -> Checkpoint | None: | ||
| del run_id, partition_id | ||
| return None | ||
|
|
||
| def save(self, checkpoint: Checkpoint) -> None: | ||
| del checkpoint | ||
|
|
||
|
|
||
| class EnvironmentSecretResolver: | ||
| """Resolve local secret references from environment variables.""" | ||
|
|
||
| def resolve(self, reference: str) -> str | None: | ||
| return os.environ.get(reference) | ||
|
|
||
|
|
||
| class NullEventPublisher: | ||
| """Discard events for callers that consume the returned iterator.""" | ||
|
|
||
| def publish(self, event: RunEvent) -> None: | ||
| del event | ||
|
|
||
|
|
||
| class InputReviewPort: | ||
| """Portable stdin reviewer used by the local Python API.""" | ||
|
|
||
| def approve_transform(self, generated_code: str) -> bool: | ||
| print("\nAI-generated transform code:\n") | ||
| print(generated_code) | ||
| try: | ||
| answer = input("Execute this code? [y/N]: ").strip().lower() | ||
| except (EOFError, KeyboardInterrupt): | ||
| return False | ||
| return answer in {"y", "yes"} |
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,38 @@ | ||
| """Versioned application boundary for Loafer clients.""" | ||
|
|
||
| from loafer.application.local import get_local_application | ||
| from loafer.application.service import LocalApplicationService, RunPipeline | ||
| from loafer.contracts import ( | ||
| BatchEnvelope, | ||
| Checkpoint, | ||
| ConnectorCatalog, | ||
| ExecutionPlan, | ||
| RunEvent, | ||
| RunRequest, | ||
| RunResult, | ||
| RunSnapshot, | ||
| RunStatus, | ||
| StageStatus, | ||
| ValidationResult, | ||
| ) | ||
| from loafer.ports.runtime import CancellationPort, CheckpointPort, SecretResolver | ||
|
|
||
| __all__ = [ | ||
| "BatchEnvelope", | ||
| "CancellationPort", | ||
| "Checkpoint", | ||
| "CheckpointPort", | ||
| "ConnectorCatalog", | ||
| "ExecutionPlan", | ||
| "LocalApplicationService", | ||
| "RunEvent", | ||
| "RunPipeline", | ||
| "RunRequest", | ||
| "RunResult", | ||
| "RunSnapshot", | ||
| "RunStatus", | ||
| "SecretResolver", | ||
| "StageStatus", | ||
| "ValidationResult", | ||
| "get_local_application", | ||
| ] | ||
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,32 @@ | ||
| """Local composition root for the application service.""" | ||
|
|
||
| from __future__ import annotations | ||
|
|
||
| from loafer.adapters.runtime import ( | ||
| EnvironmentSecretResolver, | ||
| InputReviewPort, | ||
| NeverCancelled, | ||
| NullCheckpointStore, | ||
| NullEventPublisher, | ||
| ) | ||
| from loafer.application.service import LocalApplicationService, RunPipeline | ||
| from loafer.engine import ProviderFactory | ||
| from loafer.ports.runtime import ReviewPort | ||
|
|
||
|
|
||
| def get_local_application( | ||
| *, | ||
| reviewer: ReviewPort | None = None, | ||
| provider_factory: ProviderFactory | None = None, | ||
| ) -> LocalApplicationService: | ||
| """Build the synchronous local application service.""" | ||
| return LocalApplicationService( | ||
| RunPipeline( | ||
| cancellation=NeverCancelled(), | ||
| checkpoints=NullCheckpointStore(), | ||
| secrets=EnvironmentSecretResolver(), | ||
| events=NullEventPublisher(), | ||
| reviewer=reviewer or InputReviewPort(), | ||
| provider_factory=provider_factory, | ||
| ) | ||
| ) |
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.
📐 Maintainability & Code Quality | 🟠 Major | ⚡ Quick win
Public boundary omits
EventPublisherandReviewPort.All five runtime ports (
CancellationPort,CheckpointPort,SecretResolver,EventPublisher,ReviewPort) are part of the application boundary per the PR objectives ("cancellation, checkpoints, secrets, events, and transform review"), but only three are re-exported here. New clients implementing a custom event publisher or reviewer would have to import from the internalloafer.ports.runtimemodule instead of this versioned boundary package.♻️ Proposed fix
📝 Committable suggestion
🤖 Prompt for AI Agents