Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion src/aws_durable_execution_sdk_python/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

# Main context - used in every durable function
# Helper decorators - commonly used for step functions
# Concurrency
from aws_durable_execution_sdk_python.concurrency.models import BatchResult
from aws_durable_execution_sdk_python.context import (
DurableContext,
durable_step,
Expand All @@ -20,7 +22,7 @@
from aws_durable_execution_sdk_python.execution import durable_execution

# Essential context types - passed to user functions
from aws_durable_execution_sdk_python.types import BatchResult, StepContext
from aws_durable_execution_sdk_python.types import StepContext

__all__ = [
"BatchResult",
Expand Down
21 changes: 21 additions & 0 deletions src/aws_durable_execution_sdk_python/context.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import hashlib
import logging
from dataclasses import dataclass
from typing import TYPE_CHECKING, Any, Concatenate, Generic, ParamSpec, TypeVar

from aws_durable_execution_sdk_python.config import (
Expand Down Expand Up @@ -74,6 +75,20 @@
PASS_THROUGH_SERDES: SerDes[Any] = PassThroughSerDes()


@dataclass(frozen=True)
class ExecutionContext:
"""Readonly metadata about the current durable execution context.

This class provides immutable access to execution-level metadata.

Attributes:
durable_execution_arn: The Amazon Resource Name (ARN) of the current
durable execution.
"""

durable_execution_arn: str


def durable_step(
func: Callable[Concatenate[StepContext, Params], T],
) -> Callable[Params, Callable[[StepContext], T]]:
Expand Down Expand Up @@ -218,11 +233,13 @@ class DurableContext(DurableContextProtocol):
def __init__(
self,
state: ExecutionState,
execution_context: ExecutionContext,
lambda_context: LambdaContext | None = None,
parent_id: str | None = None,
logger: Logger | None = None,
) -> None:
self.state: ExecutionState = state
self.execution_context: ExecutionContext = execution_context
self.lambda_context = lambda_context
self._parent_id: str | None = parent_id
self._step_counter: OrderedCounter = OrderedCounter()
Expand All @@ -245,6 +262,9 @@ def from_lambda_context(
):
return DurableContext(
state=state,
execution_context=ExecutionContext(
durable_execution_arn=state.durable_execution_arn
),
lambda_context=lambda_context,
parent_id=None,
)
Expand All @@ -254,6 +274,7 @@ def create_child_context(self, parent_id: str) -> DurableContext:
logger.debug("Creating child context for parent %s", parent_id)
return DurableContext(
state=self.state,
execution_context=self.execution_context,
lambda_context=self.lambda_context,
parent_id=parent_id,
logger=self.logger.with_log_info(
Expand Down
Loading
Loading