-
Notifications
You must be signed in to change notification settings - Fork 17
[Feature]: add plugin interface #371
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
Open
zhongkechen
wants to merge
1
commit into
main
Choose a base branch
from
hooks
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| #!/bin/sh | ||
|
|
||
| if hatch fmt --check; then | ||
| echo "Hatch fmt check passed!" | ||
| else | ||
| hatch fmt | ||
| echo "Error: hatch fmt modified your files. Please re-stage and commit again." | ||
| exit 1 | ||
| fi |
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,70 @@ | ||
| """Demonstrates handler execution without any durable operations.""" | ||
|
|
||
| import logging | ||
| from typing import Any | ||
|
|
||
| from aws_durable_execution_sdk_python import StepContext | ||
| from aws_durable_execution_sdk_python.context import ( | ||
| DurableContext, | ||
| durable_step, | ||
| durable_with_child_context, | ||
| ) | ||
| from aws_durable_execution_sdk_python.execution import durable_execution | ||
| from aws_durable_execution_sdk_python.plugin import ( | ||
| DurableExecutionPlugin, | ||
| AttemptStartInfo, | ||
| ) | ||
|
|
||
|
|
||
| class MyPlugin(DurableExecutionPlugin): | ||
| logger = logging.getLogger("MyPlugin") | ||
|
|
||
| def on_execution_start(self, info): | ||
| self.logger.info(f"Execution started: {info}") | ||
|
|
||
| def on_execution_end(self, info): | ||
| self.logger.info(f"Execution ended: {info}") | ||
|
|
||
| def on_operation_start(self, info): | ||
| self.logger.info(f"Operation started: {info}") | ||
|
|
||
| def on_operation_end(self, info): | ||
| self.logger.info(f"Operation ended: {info}") | ||
|
|
||
| def on_invocation_start(self, info): | ||
| self.logger.info(f"Invocation started: {info}") | ||
|
|
||
| def on_invocation_end(self, info): | ||
| self.logger.info(f"Invocation ended: {info}") | ||
|
|
||
| def on_operation_attempt_start(self, info: AttemptStartInfo) -> None: | ||
| self.logger.info(f"Attempt started: {info}") | ||
|
|
||
| def on_operation_attempt_end(self, info) -> None: | ||
| self.logger.info(f"Attempt ended: {info}") | ||
|
|
||
|
|
||
| @durable_step | ||
| def add_numbers(_step_context: StepContext, a: int, b: int) -> int: | ||
| return a + b | ||
|
|
||
|
|
||
| @durable_with_child_context | ||
| def add_numbers_in_child(child_context: DurableContext, a: int, b: int): | ||
| result: int = child_context.step( | ||
| add_numbers(a, b), | ||
| name="add-a-and-b", | ||
| ) | ||
| return result | ||
|
|
||
|
|
||
| @durable_execution(plugins=[MyPlugin()]) | ||
| def handler(_event: Any, context: DurableContext) -> int: | ||
| result: int = context.run_in_child_context( | ||
| add_numbers_in_child(6, 4), | ||
| name="add-6-and-4", | ||
| ) | ||
| return context.step( | ||
| add_numbers(result, 2), | ||
| name="add-result-to-2", | ||
| ) |
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,24 @@ | ||
| """Tests for step example.""" | ||
|
|
||
| import pytest | ||
| from aws_durable_execution_sdk_python.execution import InvocationStatus | ||
|
|
||
| from src.plugin import execution_with_plugin | ||
| from test.conftest import deserialize_operation_payload | ||
|
|
||
|
|
||
| @pytest.mark.example | ||
| @pytest.mark.durable_execution( | ||
| handler=execution_with_plugin.handler, | ||
| lambda_function_name="Plugin", | ||
| ) | ||
| def test_plugin(durable_runner): | ||
| """Test basic step example.""" | ||
| with durable_runner: | ||
| result = durable_runner.run(input="{}", timeout=10) | ||
|
|
||
| assert result.status is InvocationStatus.SUCCEEDED | ||
| assert deserialize_operation_payload(result.result) == 12 | ||
|
|
||
| step_result = result.get_step("add-result-to-2") | ||
| assert deserialize_operation_payload(step_result.result) == 12 |
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
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.
Uh oh!
There was an error while loading. Please reload this page.