Skip to content

Commit 84d0074

Browse files
author
Hanzhang Zeng (Roger)
committed
Add orchestration & activity trigger for durable function
Update durable triggers
1 parent 10689c0 commit 84d0074

File tree

5 files changed

+85
-1
lines changed

5 files changed

+85
-1
lines changed

azure/functions/__init__.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
from ._http_wsgi import WsgiMiddleware # NoQA
88
from ._queue import QueueMessage # NoQA
99
from ._servicebus import ServiceBusMessage # NoQA
10+
from ._durable_functions import OrchestrationContext # NoQA
1011
from .meta import get_binding_registry # NoQA
1112

1213
# Import binding implementations to register them
@@ -18,6 +19,7 @@
1819
from . import queue # NoQA
1920
from . import servicebus # NoQA
2021
from . import timer # NoQA
22+
from . import durable_functions # NoQA
2123

2224

2325
__all__ = (
@@ -35,9 +37,12 @@
3537
'EventHubEvent',
3638
'HttpRequest',
3739
'HttpResponse',
38-
'WsgiMiddleware',
3940
'InputStream',
41+
'OrchestrationContext',
4042
'QueueMessage',
4143
'ServiceBusMessage',
4244
'TimerRequest',
45+
46+
# Middlewares
47+
'WsgiMiddleware',
4348
)

azure/functions/_abc.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -300,3 +300,10 @@ def enqueued_time(self) -> typing.Optional[datetime.datetime]:
300300
@abc.abstractmethod
301301
def offset(self) -> typing.Optional[str]:
302302
pass
303+
304+
305+
class OrchestrationContext(abc.ABC):
306+
@property
307+
@abc.abstractmethod
308+
def body(self) -> str:
309+
pass

azure/functions/_durable_functions.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
from . import _abc
2+
3+
4+
class OrchestrationContext(_abc.OrchestrationContext):
5+
"""A durable function orchestration context.
6+
7+
:param str body:
8+
The body of orchestration context.
9+
"""
10+
11+
def __init__(self,
12+
body: str) -> None:
13+
self.__body = body
14+
15+
@property
16+
def body(self):
17+
return self.__body
18+
19+
def __repr__(self):
20+
return (
21+
f'<azure.OrchestrationContext '
22+
f'body={self.body}>'
23+
)

azure/functions/durable_functions.py

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
from typing import Any
2+
from azure.functions import _durable_functions
3+
4+
from . import meta
5+
6+
7+
# Durable Function Orchestration Trigger
8+
class OrchestrationTriggerConverter(meta.InConverter,
9+
binding='orchestrationTrigger',
10+
trigger=True):
11+
@classmethod
12+
def check_input_type_annotation(cls, pytype):
13+
return (issubclass(pytype, str)
14+
or issubclass(pytype, bytes)
15+
or issubclass(pytype, _durable_functions.OrchestrationContext))
16+
17+
@classmethod
18+
def decode(cls,
19+
data: meta.Datum, *,
20+
trigger_metadata) -> _durable_functions.OrchestrationContext:
21+
return _durable_functions.OrchestrationContext(data.value)
22+
23+
@classmethod
24+
def has_implicit_output(cls) -> bool:
25+
return True
26+
27+
28+
# Durable Function Activity Trigger
29+
class ActivityTriggerConverter(meta.InConverter,
30+
binding='activityTrigger',
31+
trigger=True):
32+
@classmethod
33+
def check_input_type_annotation(cls, pytype):
34+
# Activity Trigger's arguments should accept any types
35+
return True
36+
37+
@classmethod
38+
def decode(cls,
39+
data: meta.Datum, *,
40+
trigger_metadata) -> Any:
41+
return data.value
42+
43+
@classmethod
44+
def has_implicit_output(cls) -> bool:
45+
return True

azure/functions/meta.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -266,6 +266,10 @@ def check_input_type_annotation(cls, pytype: type) -> bool:
266266
def decode(cls, data: Datum, *, trigger_metadata) -> typing.Any:
267267
raise NotImplementedError
268268

269+
@abc.abstractclassmethod
270+
def has_implicit_output(cls) -> bool:
271+
return False
272+
269273

270274
class OutConverter(_BaseConverter, binding=None):
271275

0 commit comments

Comments
 (0)