-
Notifications
You must be signed in to change notification settings - Fork 24
Add chained invoke to the local runner #731
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
139 changes: 139 additions & 0 deletions
139
...thon-testing/src/aws_durable_execution_sdk_python_testing/checkpoint/processors/invoke.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,139 @@ | ||
| """Chained invoke operation processor for handling CHAINED_INVOKE operation updates.""" | ||
|
|
||
| from __future__ import annotations | ||
|
|
||
| import datetime | ||
| from dataclasses import replace | ||
| from typing import TYPE_CHECKING | ||
|
|
||
| from aws_durable_execution_sdk_python.lambda_service import ( | ||
| ChainedInvokeDetails, | ||
| ErrorObject, | ||
| Operation, | ||
| OperationAction, | ||
| OperationStatus, | ||
| OperationUpdate, | ||
| ) | ||
|
|
||
| from aws_durable_execution_sdk_python_testing.checkpoint.processors.base import ( | ||
| OperationProcessor, | ||
| ) | ||
| from aws_durable_execution_sdk_python_testing.exceptions import ( | ||
| InvalidParameterValueException, | ||
| ) | ||
|
|
||
| if TYPE_CHECKING: | ||
| from collections.abc import Callable | ||
|
|
||
| from aws_durable_execution_sdk_python_testing.observer import ExecutionNotifier | ||
|
|
||
|
|
||
| class ChainedInvokeProcessor(OperationProcessor): | ||
| """Processes CHAINED_INVOKE operation updates. | ||
|
|
||
| The service resolves the target before it schedules anything. Its | ||
| checkpoint response then carries the operation STARTED, because the | ||
| scheduling event is written as part of completing the checkpoint, | ||
| or FAILED when the target could not be resolved, so the handler | ||
| sees such a failure in the response to its own checkpoint and | ||
| raises without suspending. This processor does the same with | ||
| ``preflight``: a START update whose target fails the preflight | ||
| comes back FAILED with that error; otherwise it comes back STARTED | ||
| and raises a :class:`ChainedInvokeStarted` effect for the caller to | ||
| dispatch the target once the checkpoint write completes. The | ||
| operation holds STARTED until its terminal transition, so a handler | ||
| observing it sees exactly one status change; the target's terminal | ||
| state completes it. Completion is never a handler checkpoint, so | ||
| START is the only accepted action. | ||
| """ | ||
|
|
||
| def __init__(self, preflight: Callable[[str], ErrorObject | None] | None = None): | ||
| """``preflight`` resolves a target at checkpoint time; without it | ||
| every target is dispatched and any failure arrives later.""" | ||
| self._preflight = preflight | ||
|
|
||
| def process( | ||
| self, | ||
| update: OperationUpdate, | ||
| current_op: Operation | None, | ||
| notifier: ExecutionNotifier, | ||
| execution_arn: str, | ||
| now: datetime.datetime, | ||
| ) -> Operation: | ||
| """Process CHAINED_INVOKE operation update.""" | ||
| match update.action: | ||
| case OperationAction.START: | ||
| options = update.chained_invoke_options | ||
| if options is None: | ||
| msg_options_required: str = ( | ||
| "Update for CHAINED_INVOKE operation requires " | ||
| "ChainedInvokeOptions." | ||
| ) | ||
| raise InvalidParameterValueException(msg_options_required) | ||
|
|
||
| start_timestamp: datetime.datetime | None = self._get_start_time( | ||
| current_op, now | ||
| ) | ||
| error: ErrorObject | None = ( | ||
| self._preflight(options.function_name) | ||
| if self._preflight is not None | ||
| else None | ||
| ) | ||
| if error is not None: | ||
| return Operation( | ||
| operation_id=update.operation_id, | ||
| parent_id=update.parent_id, | ||
| name=update.name, | ||
| start_timestamp=start_timestamp, | ||
| end_timestamp=now, | ||
| operation_type=update.operation_type, | ||
| status=OperationStatus.FAILED, | ||
| sub_type=update.sub_type, | ||
| chained_invoke_details=ChainedInvokeDetails( | ||
| result=None, error=error | ||
| ), | ||
| ) | ||
|
|
||
| operation: Operation = Operation( | ||
| operation_id=update.operation_id, | ||
| parent_id=update.parent_id, | ||
| name=update.name, | ||
| start_timestamp=start_timestamp, | ||
| end_timestamp=None, | ||
| operation_type=update.operation_type, | ||
| status=OperationStatus.STARTED, | ||
| sub_type=update.sub_type, | ||
| chained_invoke_details=ChainedInvokeDetails( | ||
| result=None, error=None | ||
| ), | ||
| ) | ||
|
|
||
| notifier.notify_chained_invoke_started( | ||
|
yaythomas marked this conversation as resolved.
yaythomas marked this conversation as resolved.
|
||
| execution_arn=execution_arn, | ||
| operation_id=update.operation_id, | ||
| function_name=options.function_name, | ||
| tenant_id=options.tenant_id, | ||
| payload=update.payload, | ||
| ) | ||
|
yaythomas marked this conversation as resolved.
|
||
| return operation | ||
| case _: | ||
| msg_invalid_action: str = "Invalid action for CHAINED_INVOKE operation." | ||
| raise InvalidParameterValueException(msg_invalid_action) | ||
|
|
||
| def stored_update( | ||
| self, | ||
| update: OperationUpdate, | ||
| current_op: Operation | None, | ||
| updated_op: Operation, | ||
| ) -> OperationUpdate: | ||
| """Keep no input for a chained invoke that failed before starting. | ||
|
|
||
| The service stores no input payload when the target cannot be | ||
| resolved: it records a payload size of zero and an empty payload | ||
| location, and its history shows the function name and the error | ||
| without the input. So the runner stores the update without its | ||
| payload, which also keeps it out of the operation's size. | ||
| """ | ||
| if current_op is None and updated_op.status is OperationStatus.FAILED: | ||
| return replace(update, payload=None) | ||
| return update | ||
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.