async-durable-execution-runner 2.0.0a1__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- LICENSE +175 -0
- NOTICE +8 -0
- VERSION.py +5 -0
- async_durable_execution_runner/__about__.py +33 -0
- async_durable_execution_runner/__init__.py +23 -0
- async_durable_execution_runner/checkpoint/__init__.py +1 -0
- async_durable_execution_runner/checkpoint/processor.py +101 -0
- async_durable_execution_runner/checkpoint/processors/__init__.py +1 -0
- async_durable_execution_runner/checkpoint/processors/base.py +199 -0
- async_durable_execution_runner/checkpoint/processors/callback.py +89 -0
- async_durable_execution_runner/checkpoint/processors/context.py +59 -0
- async_durable_execution_runner/checkpoint/processors/execution.py +52 -0
- async_durable_execution_runner/checkpoint/processors/step.py +124 -0
- async_durable_execution_runner/checkpoint/processors/wait.py +95 -0
- async_durable_execution_runner/checkpoint/transformer.py +104 -0
- async_durable_execution_runner/checkpoint/validators/__init__.py +1 -0
- async_durable_execution_runner/checkpoint/validators/checkpoint.py +242 -0
- async_durable_execution_runner/checkpoint/validators/operations/__init__.py +1 -0
- async_durable_execution_runner/checkpoint/validators/operations/callback.py +45 -0
- async_durable_execution_runner/checkpoint/validators/operations/context.py +73 -0
- async_durable_execution_runner/checkpoint/validators/operations/execution.py +47 -0
- async_durable_execution_runner/checkpoint/validators/operations/invoke.py +56 -0
- async_durable_execution_runner/checkpoint/validators/operations/step.py +106 -0
- async_durable_execution_runner/checkpoint/validators/operations/wait.py +54 -0
- async_durable_execution_runner/checkpoint/validators/transitions.py +66 -0
- async_durable_execution_runner/cli.py +498 -0
- async_durable_execution_runner/client.py +50 -0
- async_durable_execution_runner/exceptions.py +288 -0
- async_durable_execution_runner/execution.py +444 -0
- async_durable_execution_runner/executor.py +1234 -0
- async_durable_execution_runner/invoker.py +340 -0
- async_durable_execution_runner/model.py +3296 -0
- async_durable_execution_runner/observer.py +144 -0
- async_durable_execution_runner/py.typed +1 -0
- async_durable_execution_runner/runner.py +1167 -0
- async_durable_execution_runner/scheduler.py +246 -0
- async_durable_execution_runner/stores/__init__.py +1 -0
- async_durable_execution_runner/stores/base.py +147 -0
- async_durable_execution_runner/stores/filesystem.py +79 -0
- async_durable_execution_runner/stores/memory.py +38 -0
- async_durable_execution_runner/stores/sqlite.py +273 -0
- async_durable_execution_runner/token.py +49 -0
- async_durable_execution_runner/web/__init__.py +1 -0
- async_durable_execution_runner/web/errors.py +8 -0
- async_durable_execution_runner/web/handlers.py +813 -0
- async_durable_execution_runner/web/models.py +266 -0
- async_durable_execution_runner/web/routes.py +692 -0
- async_durable_execution_runner/web/serialization.py +235 -0
- async_durable_execution_runner/web/server.py +243 -0
- async_durable_execution_runner-2.0.0a1.dist-info/METADATA +238 -0
- async_durable_execution_runner-2.0.0a1.dist-info/RECORD +55 -0
- async_durable_execution_runner-2.0.0a1.dist-info/WHEEL +4 -0
- async_durable_execution_runner-2.0.0a1.dist-info/entry_points.txt +2 -0
- async_durable_execution_runner-2.0.0a1.dist-info/licenses/LICENSE +175 -0
- async_durable_execution_runner-2.0.0a1.dist-info/licenses/NOTICE +1 -0
LICENSE
ADDED
|
@@ -0,0 +1,175 @@
|
|
|
1
|
+
|
|
2
|
+
Apache License
|
|
3
|
+
Version 2.0, January 2004
|
|
4
|
+
http://www.apache.org/licenses/
|
|
5
|
+
|
|
6
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
7
|
+
|
|
8
|
+
1. Definitions.
|
|
9
|
+
|
|
10
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
11
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
12
|
+
|
|
13
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
14
|
+
the copyright owner that is granting the License.
|
|
15
|
+
|
|
16
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
17
|
+
other entities that control, are controlled by, or are under common
|
|
18
|
+
control with that entity. For the purposes of this definition,
|
|
19
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
20
|
+
direction or management of such entity, whether by contract or
|
|
21
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
22
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
23
|
+
|
|
24
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
25
|
+
exercising permissions granted by this License.
|
|
26
|
+
|
|
27
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
28
|
+
including but not limited to software source code, documentation
|
|
29
|
+
source, and configuration files.
|
|
30
|
+
|
|
31
|
+
"Object" form shall mean any form resulting from mechanical
|
|
32
|
+
transformation or translation of a Source form, including but
|
|
33
|
+
not limited to compiled object code, generated documentation,
|
|
34
|
+
and conversions to other media types.
|
|
35
|
+
|
|
36
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
37
|
+
Object form, made available under the License, as indicated by a
|
|
38
|
+
copyright notice that is included in or attached to the work
|
|
39
|
+
(an example is provided in the Appendix below).
|
|
40
|
+
|
|
41
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
42
|
+
form, that is based on (or derived from) the Work and for which the
|
|
43
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
44
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
45
|
+
of this License, Derivative Works shall not include works that remain
|
|
46
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
47
|
+
the Work and Derivative Works thereof.
|
|
48
|
+
|
|
49
|
+
"Contribution" shall mean any work of authorship, including
|
|
50
|
+
the original version of the Work and any modifications or additions
|
|
51
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
52
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
53
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
54
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
55
|
+
means any form of electronic, verbal, or written communication sent
|
|
56
|
+
to the Licensor or its representatives, including but not limited to
|
|
57
|
+
communication on electronic mailing lists, source code control systems,
|
|
58
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
59
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
60
|
+
excluding communication that is conspicuously marked or otherwise
|
|
61
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
62
|
+
|
|
63
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
64
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
65
|
+
subsequently incorporated within the Work.
|
|
66
|
+
|
|
67
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
68
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
69
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
70
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
71
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
72
|
+
Work and such Derivative Works in Source or Object form.
|
|
73
|
+
|
|
74
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
75
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
76
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
77
|
+
(except as stated in this section) patent license to make, have made,
|
|
78
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
79
|
+
where such license applies only to those patent claims licensable
|
|
80
|
+
by such Contributor that are necessarily infringed by their
|
|
81
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
82
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
83
|
+
institute patent litigation against any entity (including a
|
|
84
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
85
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
86
|
+
or contributory patent infringement, then any patent licenses
|
|
87
|
+
granted to You under this License for that Work shall terminate
|
|
88
|
+
as of the date such litigation is filed.
|
|
89
|
+
|
|
90
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
91
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
92
|
+
modifications, and in Source or Object form, provided that You
|
|
93
|
+
meet the following conditions:
|
|
94
|
+
|
|
95
|
+
(a) You must give any other recipients of the Work or
|
|
96
|
+
Derivative Works a copy of this License; and
|
|
97
|
+
|
|
98
|
+
(b) You must cause any modified files to carry prominent notices
|
|
99
|
+
stating that You changed the files; and
|
|
100
|
+
|
|
101
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
102
|
+
that You distribute, all copyright, patent, trademark, and
|
|
103
|
+
attribution notices from the Source form of the Work,
|
|
104
|
+
excluding those notices that do not pertain to any part of
|
|
105
|
+
the Derivative Works; and
|
|
106
|
+
|
|
107
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
108
|
+
distribution, then any Derivative Works that You distribute must
|
|
109
|
+
include a readable copy of the attribution notices contained
|
|
110
|
+
within such NOTICE file, excluding those notices that do not
|
|
111
|
+
pertain to any part of the Derivative Works, in at least one
|
|
112
|
+
of the following places: within a NOTICE text file distributed
|
|
113
|
+
as part of the Derivative Works; within the Source form or
|
|
114
|
+
documentation, if provided along with the Derivative Works; or,
|
|
115
|
+
within a display generated by the Derivative Works, if and
|
|
116
|
+
wherever such third-party notices normally appear. The contents
|
|
117
|
+
of the NOTICE file are for informational purposes only and
|
|
118
|
+
do not modify the License. You may add Your own attribution
|
|
119
|
+
notices within Derivative Works that You distribute, alongside
|
|
120
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
121
|
+
that such additional attribution notices cannot be construed
|
|
122
|
+
as modifying the License.
|
|
123
|
+
|
|
124
|
+
You may add Your own copyright statement to Your modifications and
|
|
125
|
+
may provide additional or different license terms and conditions
|
|
126
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
127
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
128
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
129
|
+
the conditions stated in this License.
|
|
130
|
+
|
|
131
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
132
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
133
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
134
|
+
this License, without any additional terms or conditions.
|
|
135
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
136
|
+
the terms of any separate license agreement you may have executed
|
|
137
|
+
with Licensor regarding such Contributions.
|
|
138
|
+
|
|
139
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
140
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
141
|
+
except as required for reasonable and customary use in describing the
|
|
142
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
143
|
+
|
|
144
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
145
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
146
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
147
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
148
|
+
implied, including, without limitation, any warranties or conditions
|
|
149
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
150
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
151
|
+
appropriateness of using or redistributing the Work and assume any
|
|
152
|
+
risks associated with Your exercise of permissions under this License.
|
|
153
|
+
|
|
154
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
155
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
156
|
+
unless required by applicable law (such as deliberate and grossly
|
|
157
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
158
|
+
liable to You for damages, including any direct, indirect, special,
|
|
159
|
+
incidental, or consequential damages of any character arising as a
|
|
160
|
+
result of this License or out of the use or inability to use the
|
|
161
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
162
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
163
|
+
other commercial damages or losses), even if such Contributor
|
|
164
|
+
has been advised of the possibility of such damages.
|
|
165
|
+
|
|
166
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
167
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
168
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
169
|
+
or other liability obligations and/or rights consistent with this
|
|
170
|
+
License. However, in accepting such obligations, You may act only
|
|
171
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
172
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
173
|
+
defend, and hold each Contributor harmless for any liability
|
|
174
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
175
|
+
of your accepting any such warranty or additional liability.
|
NOTICE
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
2
|
+
|
|
3
|
+
This repository is a modified fork of software originally released by
|
|
4
|
+
Amazon.com, Inc. or its affiliates under the Apache License 2.0.
|
|
5
|
+
|
|
6
|
+
Fork modifications and continued maintenance:
|
|
7
|
+
Copyright 2026 Zhongke Chen
|
|
8
|
+
Repository: https://github.com/zhongkechen/async-durable-execution
|
VERSION.py
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
# SPDX-FileCopyrightText: 2025-present Amazon.com, Inc. or its affiliates.
|
|
2
|
+
#
|
|
3
|
+
# SPDX-License-Identifier: Apache-2.0
|
|
4
|
+
from importlib.metadata import PackageNotFoundError, version
|
|
5
|
+
from pathlib import Path
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
_DIST_NAME = "async-durable-execution-runner"
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
def _read_repo_version() -> str:
|
|
12
|
+
version_file = _find_version_file()
|
|
13
|
+
if version_file is None:
|
|
14
|
+
return "0.0.0"
|
|
15
|
+
|
|
16
|
+
namespace: dict[str, str] = {}
|
|
17
|
+
exec(version_file.read_text(encoding="utf-8"), namespace)
|
|
18
|
+
return namespace["__version__"]
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
def _find_version_file() -> Path | None:
|
|
22
|
+
current = Path(__file__).resolve()
|
|
23
|
+
for parent in current.parents:
|
|
24
|
+
candidate = parent / "VERSION.py"
|
|
25
|
+
if candidate.exists():
|
|
26
|
+
return candidate
|
|
27
|
+
return None
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
try:
|
|
31
|
+
__version__ = version(_DIST_NAME)
|
|
32
|
+
except PackageNotFoundError:
|
|
33
|
+
__version__ = _read_repo_version()
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
"""DurableExecutionsPythonTestingLibrary module."""
|
|
2
|
+
|
|
3
|
+
from async_durable_execution_runner.runner import (
|
|
4
|
+
DurableChildContextTestRunner,
|
|
5
|
+
DurableFunctionCloudTestRunner,
|
|
6
|
+
DurableFunctionTestResult,
|
|
7
|
+
DurableFunctionTestRunner,
|
|
8
|
+
WebRunner,
|
|
9
|
+
WebRunnerConfig,
|
|
10
|
+
)
|
|
11
|
+
|
|
12
|
+
from async_durable_execution_runner.__about__ import __version__
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
__all__ = [
|
|
16
|
+
"DurableChildContextTestRunner",
|
|
17
|
+
"DurableFunctionCloudTestRunner",
|
|
18
|
+
"DurableFunctionTestResult",
|
|
19
|
+
"DurableFunctionTestRunner",
|
|
20
|
+
"WebRunner",
|
|
21
|
+
"WebRunnerConfig",
|
|
22
|
+
"__version__",
|
|
23
|
+
]
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"""Checkpoint processing module for handling OperationUpdate transformations."""
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
"""Main checkpoint processor that orchestrates operation transformations."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
from typing import TYPE_CHECKING
|
|
6
|
+
|
|
7
|
+
from async_durable_execution.lambda_service import (
|
|
8
|
+
CheckpointOutput,
|
|
9
|
+
CheckpointUpdatedExecutionState,
|
|
10
|
+
OperationUpdate,
|
|
11
|
+
StateOutput,
|
|
12
|
+
)
|
|
13
|
+
|
|
14
|
+
from async_durable_execution_runner.checkpoint.transformer import (
|
|
15
|
+
OperationTransformer,
|
|
16
|
+
)
|
|
17
|
+
from async_durable_execution_runner.checkpoint.validators.checkpoint import (
|
|
18
|
+
CheckpointValidator,
|
|
19
|
+
)
|
|
20
|
+
from async_durable_execution_runner.exceptions import (
|
|
21
|
+
InvalidParameterValueException,
|
|
22
|
+
)
|
|
23
|
+
from async_durable_execution_runner.observer import ExecutionNotifier
|
|
24
|
+
from async_durable_execution_runner.token import CheckpointToken
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
if TYPE_CHECKING:
|
|
28
|
+
from async_durable_execution_runner.execution import Execution
|
|
29
|
+
from async_durable_execution_runner.scheduler import Scheduler
|
|
30
|
+
from async_durable_execution_runner.stores.base import ExecutionStore
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
class CheckpointProcessor:
|
|
34
|
+
"""Handle OperationUpdate transformations and execution state updates."""
|
|
35
|
+
|
|
36
|
+
def __init__(self, store: ExecutionStore, scheduler: Scheduler):
|
|
37
|
+
self._store = store
|
|
38
|
+
self._scheduler = scheduler
|
|
39
|
+
self._notifier = ExecutionNotifier()
|
|
40
|
+
self._transformer = OperationTransformer()
|
|
41
|
+
|
|
42
|
+
def add_execution_observer(self, observer) -> None:
|
|
43
|
+
"""Add observer for execution events."""
|
|
44
|
+
self._notifier.add_observer(observer)
|
|
45
|
+
|
|
46
|
+
def process_checkpoint(
|
|
47
|
+
self,
|
|
48
|
+
checkpoint_token: str,
|
|
49
|
+
updates: list[OperationUpdate],
|
|
50
|
+
client_token: str | None, # noqa: ARG002
|
|
51
|
+
) -> CheckpointOutput:
|
|
52
|
+
"""Process checkpoint updates and return result with updated execution state."""
|
|
53
|
+
# 1. Get current execution state
|
|
54
|
+
token: CheckpointToken = CheckpointToken.from_str(checkpoint_token)
|
|
55
|
+
execution: Execution = self._store.load(token.execution_arn)
|
|
56
|
+
|
|
57
|
+
# 2. Validate checkpoint token
|
|
58
|
+
if execution.is_complete or token.token_sequence != execution.token_sequence:
|
|
59
|
+
msg: str = "Invalid checkpoint token"
|
|
60
|
+
|
|
61
|
+
raise InvalidParameterValueException(msg)
|
|
62
|
+
|
|
63
|
+
# 3. Validate all updates, state transitions are valid, sizes etc.
|
|
64
|
+
CheckpointValidator.validate_input(updates, execution)
|
|
65
|
+
|
|
66
|
+
# 4. Transform OperationUpdate -> Operation and schedule future replays
|
|
67
|
+
updated_operations, all_updates = self._transformer.process_updates(
|
|
68
|
+
updates=updates,
|
|
69
|
+
current_operations=execution.operations,
|
|
70
|
+
notifier=self._notifier,
|
|
71
|
+
execution_arn=token.execution_arn,
|
|
72
|
+
)
|
|
73
|
+
|
|
74
|
+
# 5. Generate a new checkpoint token and save updated operations
|
|
75
|
+
new_checkpoint_token = execution.get_new_checkpoint_token()
|
|
76
|
+
execution.operations = updated_operations
|
|
77
|
+
execution.updates.extend(all_updates)
|
|
78
|
+
self._store.update(execution)
|
|
79
|
+
|
|
80
|
+
# 6. Return checkpoint result
|
|
81
|
+
return CheckpointOutput(
|
|
82
|
+
checkpoint_token=new_checkpoint_token,
|
|
83
|
+
new_execution_state=CheckpointUpdatedExecutionState(
|
|
84
|
+
operations=execution.get_navigable_operations(), next_marker=None
|
|
85
|
+
),
|
|
86
|
+
)
|
|
87
|
+
|
|
88
|
+
def get_execution_state(
|
|
89
|
+
self,
|
|
90
|
+
checkpoint_token: str,
|
|
91
|
+
next_marker: str, # noqa: ARG002
|
|
92
|
+
max_items: int = 1000, # noqa: ARG002
|
|
93
|
+
) -> StateOutput:
|
|
94
|
+
"""Get current execution state."""
|
|
95
|
+
token: CheckpointToken = CheckpointToken.from_str(checkpoint_token)
|
|
96
|
+
execution: Execution = self._store.load(token.execution_arn)
|
|
97
|
+
|
|
98
|
+
# TODO: paging when size or max
|
|
99
|
+
return StateOutput(
|
|
100
|
+
operations=execution.get_navigable_operations(), next_marker=None
|
|
101
|
+
)
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"""Checkpoint processors module."""
|
|
@@ -0,0 +1,199 @@
|
|
|
1
|
+
"""Base processor class for operation transformations."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
import datetime
|
|
6
|
+
from datetime import timedelta
|
|
7
|
+
from typing import TYPE_CHECKING
|
|
8
|
+
|
|
9
|
+
from async_durable_execution.lambda_service import (
|
|
10
|
+
CallbackDetails,
|
|
11
|
+
ChainedInvokeDetails,
|
|
12
|
+
ContextDetails,
|
|
13
|
+
ExecutionDetails,
|
|
14
|
+
Operation,
|
|
15
|
+
OperationAction,
|
|
16
|
+
OperationStatus,
|
|
17
|
+
OperationType,
|
|
18
|
+
OperationUpdate,
|
|
19
|
+
StepDetails,
|
|
20
|
+
WaitDetails,
|
|
21
|
+
)
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
if TYPE_CHECKING:
|
|
25
|
+
from async_durable_execution_runner.observer import ExecutionNotifier
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
class OperationProcessor:
|
|
29
|
+
"""Base class for processing OperationUpdate to Operation transformations."""
|
|
30
|
+
|
|
31
|
+
def process(
|
|
32
|
+
self,
|
|
33
|
+
update: OperationUpdate,
|
|
34
|
+
current_op: Operation | None,
|
|
35
|
+
notifier: ExecutionNotifier,
|
|
36
|
+
execution_arn: str,
|
|
37
|
+
) -> Operation | None:
|
|
38
|
+
"""Process an operation update and return the transformed operation."""
|
|
39
|
+
raise NotImplementedError
|
|
40
|
+
|
|
41
|
+
def _get_start_time(
|
|
42
|
+
self, current_operation: Operation | None
|
|
43
|
+
) -> datetime.datetime | None:
|
|
44
|
+
start_time: datetime.datetime | None = (
|
|
45
|
+
current_operation.start_timestamp
|
|
46
|
+
if current_operation
|
|
47
|
+
else datetime.datetime.now(tz=datetime.UTC)
|
|
48
|
+
)
|
|
49
|
+
return start_time
|
|
50
|
+
|
|
51
|
+
def _get_end_time(
|
|
52
|
+
self, current_operation: Operation | None, status: OperationStatus
|
|
53
|
+
) -> datetime.datetime | None:
|
|
54
|
+
"""Get end timestamp for operation based on current state and status."""
|
|
55
|
+
if current_operation and current_operation.end_timestamp:
|
|
56
|
+
return current_operation.end_timestamp
|
|
57
|
+
if status in {
|
|
58
|
+
OperationStatus.SUCCEEDED,
|
|
59
|
+
OperationStatus.FAILED,
|
|
60
|
+
OperationStatus.CANCELLED,
|
|
61
|
+
OperationStatus.TIMED_OUT,
|
|
62
|
+
OperationStatus.STOPPED,
|
|
63
|
+
}:
|
|
64
|
+
return datetime.datetime.now(tz=datetime.UTC)
|
|
65
|
+
return None
|
|
66
|
+
|
|
67
|
+
def _create_execution_details(
|
|
68
|
+
self, update: OperationUpdate
|
|
69
|
+
) -> ExecutionDetails | None:
|
|
70
|
+
"""Create ExecutionDetails from OperationUpdate."""
|
|
71
|
+
return (
|
|
72
|
+
ExecutionDetails(input_payload=update.payload)
|
|
73
|
+
if update.operation_type == OperationType.EXECUTION
|
|
74
|
+
else None
|
|
75
|
+
)
|
|
76
|
+
|
|
77
|
+
def _create_context_details(self, update: OperationUpdate) -> ContextDetails | None:
|
|
78
|
+
"""Create ContextDetails from OperationUpdate."""
|
|
79
|
+
return (
|
|
80
|
+
ContextDetails(
|
|
81
|
+
result=update.payload,
|
|
82
|
+
error=update.error,
|
|
83
|
+
replay_children=update.context_options.replay_children
|
|
84
|
+
if update.context_options
|
|
85
|
+
else False,
|
|
86
|
+
)
|
|
87
|
+
if update.operation_type == OperationType.CONTEXT
|
|
88
|
+
else None
|
|
89
|
+
)
|
|
90
|
+
|
|
91
|
+
def _create_step_details(
|
|
92
|
+
self,
|
|
93
|
+
update: OperationUpdate,
|
|
94
|
+
current_operation: Operation | None = None,
|
|
95
|
+
) -> StepDetails | None:
|
|
96
|
+
"""Create StepDetails from OperationUpdate.
|
|
97
|
+
|
|
98
|
+
Automatically increments attempt count for RETRY, SUCCEED, and FAIL actions.
|
|
99
|
+
"""
|
|
100
|
+
|
|
101
|
+
attempt: int = 0
|
|
102
|
+
next_attempt_timestamp: datetime.datetime | None = None
|
|
103
|
+
|
|
104
|
+
if update.operation_type is OperationType.STEP:
|
|
105
|
+
if current_operation and current_operation.step_details:
|
|
106
|
+
attempt = current_operation.step_details.attempt
|
|
107
|
+
next_attempt_timestamp = (
|
|
108
|
+
current_operation.step_details.next_attempt_timestamp
|
|
109
|
+
)
|
|
110
|
+
# Increment attempt for RETRY, SUCCEED, and FAIL actions
|
|
111
|
+
if update.action in {
|
|
112
|
+
OperationAction.RETRY,
|
|
113
|
+
OperationAction.SUCCEED,
|
|
114
|
+
OperationAction.FAIL,
|
|
115
|
+
}:
|
|
116
|
+
attempt += 1
|
|
117
|
+
return StepDetails(
|
|
118
|
+
attempt=attempt,
|
|
119
|
+
next_attempt_timestamp=next_attempt_timestamp,
|
|
120
|
+
result=update.payload,
|
|
121
|
+
error=update.error,
|
|
122
|
+
)
|
|
123
|
+
|
|
124
|
+
return None
|
|
125
|
+
|
|
126
|
+
def _create_callback_details(
|
|
127
|
+
self, update: OperationUpdate
|
|
128
|
+
) -> CallbackDetails | None:
|
|
129
|
+
"""Create CallbackDetails from OperationUpdate."""
|
|
130
|
+
return (
|
|
131
|
+
CallbackDetails(
|
|
132
|
+
callback_id="placeholder", result=update.payload, error=update.error
|
|
133
|
+
)
|
|
134
|
+
if update.operation_type == OperationType.CALLBACK
|
|
135
|
+
else None
|
|
136
|
+
)
|
|
137
|
+
|
|
138
|
+
def _create_invoke_details(
|
|
139
|
+
self, update: OperationUpdate
|
|
140
|
+
) -> ChainedInvokeDetails | None:
|
|
141
|
+
"""Create ChainedInvokeDetails from OperationUpdate."""
|
|
142
|
+
if (
|
|
143
|
+
update.operation_type == OperationType.CHAINED_INVOKE
|
|
144
|
+
and update.chained_invoke_options
|
|
145
|
+
):
|
|
146
|
+
return ChainedInvokeDetails(result=update.payload, error=update.error)
|
|
147
|
+
return None
|
|
148
|
+
|
|
149
|
+
def _translate_update_to_operation(
|
|
150
|
+
self,
|
|
151
|
+
update: OperationUpdate,
|
|
152
|
+
current_operation: Operation | None,
|
|
153
|
+
status: OperationStatus,
|
|
154
|
+
) -> Operation:
|
|
155
|
+
"""Transform OperationUpdate to Operation, always creating new Operation."""
|
|
156
|
+
start_time: datetime.datetime | None = self._get_start_time(current_operation)
|
|
157
|
+
end_time: datetime.datetime | None = self._get_end_time(
|
|
158
|
+
current_operation, status
|
|
159
|
+
)
|
|
160
|
+
|
|
161
|
+
execution_details = self._create_execution_details(update)
|
|
162
|
+
context_details = self._create_context_details(update)
|
|
163
|
+
step_details = self._create_step_details(update, current_operation)
|
|
164
|
+
callback_details = self._create_callback_details(update)
|
|
165
|
+
invoke_details = self._create_invoke_details(update)
|
|
166
|
+
wait_details = self._create_wait_details(update, current_operation)
|
|
167
|
+
|
|
168
|
+
return Operation(
|
|
169
|
+
operation_id=update.operation_id,
|
|
170
|
+
parent_id=update.parent_id,
|
|
171
|
+
name=update.name,
|
|
172
|
+
start_timestamp=start_time,
|
|
173
|
+
end_timestamp=end_time,
|
|
174
|
+
operation_type=update.operation_type,
|
|
175
|
+
status=status,
|
|
176
|
+
sub_type=update.sub_type,
|
|
177
|
+
execution_details=execution_details,
|
|
178
|
+
context_details=context_details,
|
|
179
|
+
step_details=step_details,
|
|
180
|
+
callback_details=callback_details,
|
|
181
|
+
chained_invoke_details=invoke_details,
|
|
182
|
+
wait_details=wait_details,
|
|
183
|
+
)
|
|
184
|
+
|
|
185
|
+
def _create_wait_details(
|
|
186
|
+
self, update: OperationUpdate, current_operation: Operation | None
|
|
187
|
+
) -> WaitDetails | None:
|
|
188
|
+
"""Create WaitDetails from OperationUpdate."""
|
|
189
|
+
if update.operation_type == OperationType.WAIT and update.wait_options:
|
|
190
|
+
if current_operation and current_operation.wait_details:
|
|
191
|
+
scheduled_end_timestamp = (
|
|
192
|
+
current_operation.wait_details.scheduled_end_timestamp
|
|
193
|
+
)
|
|
194
|
+
else:
|
|
195
|
+
scheduled_end_timestamp = datetime.datetime.now(
|
|
196
|
+
tz=datetime.UTC
|
|
197
|
+
) + timedelta(seconds=update.wait_options.wait_seconds)
|
|
198
|
+
return WaitDetails(scheduled_end_timestamp=scheduled_end_timestamp)
|
|
199
|
+
return None
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
"""Callback operation processor for handling CALLBACK operation updates."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
import datetime
|
|
6
|
+
from typing import TYPE_CHECKING
|
|
7
|
+
|
|
8
|
+
from async_durable_execution.lambda_service import (
|
|
9
|
+
Operation,
|
|
10
|
+
OperationAction,
|
|
11
|
+
OperationStatus,
|
|
12
|
+
OperationUpdate,
|
|
13
|
+
CallbackDetails,
|
|
14
|
+
OperationType,
|
|
15
|
+
CallbackOptions,
|
|
16
|
+
)
|
|
17
|
+
from async_durable_execution_runner.checkpoint.processors.base import (
|
|
18
|
+
OperationProcessor,
|
|
19
|
+
)
|
|
20
|
+
from async_durable_execution_runner.exceptions import (
|
|
21
|
+
InvalidParameterValueException,
|
|
22
|
+
)
|
|
23
|
+
from async_durable_execution_runner.token import CallbackToken
|
|
24
|
+
|
|
25
|
+
if TYPE_CHECKING:
|
|
26
|
+
from async_durable_execution_runner.observer import ExecutionNotifier
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
class CallbackProcessor(OperationProcessor):
|
|
30
|
+
"""Processes CALLBACK operation updates with activity scheduling."""
|
|
31
|
+
|
|
32
|
+
def process(
|
|
33
|
+
self,
|
|
34
|
+
update: OperationUpdate,
|
|
35
|
+
current_op: Operation | None,
|
|
36
|
+
notifier: ExecutionNotifier, # noqa: ARG002
|
|
37
|
+
execution_arn: str, # noqa: ARG002
|
|
38
|
+
) -> Operation:
|
|
39
|
+
"""Process CALLBACK operation update with scheduler integration for activities."""
|
|
40
|
+
match update.action:
|
|
41
|
+
case OperationAction.START:
|
|
42
|
+
callback_token: CallbackToken = CallbackToken(
|
|
43
|
+
execution_arn=execution_arn,
|
|
44
|
+
operation_id=update.operation_id,
|
|
45
|
+
)
|
|
46
|
+
|
|
47
|
+
callback_id: str = callback_token.to_str()
|
|
48
|
+
|
|
49
|
+
callback_details: CallbackDetails | None = (
|
|
50
|
+
CallbackDetails(
|
|
51
|
+
callback_id=callback_id,
|
|
52
|
+
result=update.payload,
|
|
53
|
+
error=update.error,
|
|
54
|
+
)
|
|
55
|
+
if update.operation_type == OperationType.CALLBACK
|
|
56
|
+
else None
|
|
57
|
+
)
|
|
58
|
+
|
|
59
|
+
status: OperationStatus = OperationStatus.STARTED
|
|
60
|
+
|
|
61
|
+
start_time: datetime.datetime | None = self._get_start_time(current_op)
|
|
62
|
+
|
|
63
|
+
end_time: datetime.datetime | None = self._get_end_time(
|
|
64
|
+
current_op, status
|
|
65
|
+
)
|
|
66
|
+
|
|
67
|
+
operation: Operation = Operation(
|
|
68
|
+
operation_id=update.operation_id,
|
|
69
|
+
parent_id=update.parent_id,
|
|
70
|
+
name=update.name,
|
|
71
|
+
start_timestamp=start_time,
|
|
72
|
+
end_timestamp=end_time,
|
|
73
|
+
operation_type=update.operation_type,
|
|
74
|
+
status=status,
|
|
75
|
+
sub_type=update.sub_type,
|
|
76
|
+
callback_details=callback_details,
|
|
77
|
+
)
|
|
78
|
+
callback_options: CallbackOptions | None = update.callback_options
|
|
79
|
+
|
|
80
|
+
notifier.notify_callback_created(
|
|
81
|
+
execution_arn=execution_arn,
|
|
82
|
+
operation_id=update.operation_id,
|
|
83
|
+
callback_options=callback_options,
|
|
84
|
+
callback_token=callback_token,
|
|
85
|
+
)
|
|
86
|
+
return operation
|
|
87
|
+
case _:
|
|
88
|
+
msg: str = "Invalid action for CALLBACK operation."
|
|
89
|
+
raise InvalidParameterValueException(msg)
|