Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 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
28 changes: 28 additions & 0 deletions azure/functions/_durable_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,3 +109,31 @@ def __repr__(self):

def __str__(self):
return self.__body


class EntityContext(_abc.OrchestrationContext):
"""A durable function entity context.

:param str body:
The body of orchestration context json.
"""

def __init__(self,
body: Union[str, bytes]) -> None:
if isinstance(body, str):
self.__body = body
if isinstance(body, bytes):
self.__body = body.decode('utf-8')

@property
def body(self) -> str:
return self.__body

def __repr__(self):
return (
f'<azure.EntityContext '
f'body={self.body}>'
)

def __str__(self):
return self.__body
30 changes: 30 additions & 0 deletions azure/functions/durable_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,36 @@ def has_implicit_output(cls) -> bool:
return True


class EnitityTriggerConverter(meta.InConverter,
meta.OutConverter,
binding='entityTrigger',
trigger=True):
@classmethod
def check_input_type_annotation(cls, pytype):
return issubclass(pytype, _durable_functions.EntityContext)

@classmethod
def check_output_type_annotation(cls, pytype):
# Implicit output should accept any return type
return True

@classmethod
def decode(cls,
data: meta.Datum, *,
trigger_metadata) -> _durable_functions.EntityContext:
return _durable_functions.EntityContext(data.value)

@classmethod
def encode(cls, obj: typing.Any, *,
expected_type: typing.Optional[type]) -> meta.Datum:
# Durable function context should be a json
return meta.Datum(type='json', value=obj)

@classmethod
def has_implicit_output(cls) -> bool:
return True


# Durable Function Activity Trigger
class ActivityTriggerConverter(meta.InConverter,
meta.OutConverter,
Expand Down