Skip to content

Add durable functions support #623

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 5 commits into from
Feb 28, 2020
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
2 changes: 2 additions & 0 deletions azure_functions_worker/bindings/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from .context import Context
from .meta import check_input_type_annotation
from .meta import check_output_type_annotation
from .meta import has_implicit_output
from .meta import is_trigger_binding
from .meta import from_incoming_proto, to_outgoing_proto
from .out import Out
Expand All @@ -11,5 +12,6 @@
'Out', 'Context',
'is_trigger_binding',
'check_input_type_annotation', 'check_output_type_annotation',
'has_implicit_output',
'from_incoming_proto', 'to_outgoing_proto', 'TraceContext',
)
4 changes: 4 additions & 0 deletions azure_functions_worker/bindings/generic.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,3 +46,7 @@ def decode(cls, data: datumdef.Datum, *, trigger_metadata) -> typing.Any:
)

return result

@classmethod
def has_implicit_output(cls) -> bool:
return False
27 changes: 18 additions & 9 deletions azure_functions_worker/bindings/meta.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,19 @@

def get_binding_registry():
func = sys.modules.get('azure.functions')
if func is not None:
return func.get_binding_registry()
else:
return None

# If fails to acquire customer's BYO azure-functions, load the builtin
if func is None:
import azure.functions as func

return func.get_binding_registry()


def get_binding(bind_name: str) -> object:
binding = None
registry = get_binding_registry()
if registry is not None:
binding = registry.get(bind_name)

if binding is None:
binding = generic.GenericBinding

Expand All @@ -32,16 +33,24 @@ def is_trigger_binding(bind_name: str) -> bool:
return binding.has_trigger_support()


def check_input_type_annotation(binding: str, pytype: type) -> bool:
binding = get_binding(binding)
def check_input_type_annotation(bind_name: str, pytype: type) -> bool:
binding = get_binding(bind_name)
return binding.check_input_type_annotation(pytype)


def check_output_type_annotation(binding: str, pytype: type) -> bool:
binding = get_binding(binding)
def check_output_type_annotation(bind_name: str, pytype: type) -> bool:
binding = get_binding(bind_name)
return binding.check_output_type_annotation(pytype)


def has_implicit_output(bind_name: str) -> bool:
binding = get_binding(bind_name)

# If the binding does not have metaclass of meta.InConverter
# The implicit_output does not exist
return getattr(binding, 'has_implicit_output', lambda: False)()


def from_incoming_proto(
binding: str,
val: protos.TypedData, *,
Expand Down
10 changes: 9 additions & 1 deletion azure_functions_worker/functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,13 @@ def add_function(self, function_id: str,
assert return_binding_name is not None

has_return = True
elif bindings.has_implicit_output(desc.type):
# If the binding specify implicit output binding
# (e.g. orchestrationTrigger, activityTrigger)
# we should enable output even if $return is not specified
has_return = True
return_binding_name = f'{desc.type}_ret'
bound_params[name] = desc
else:
bound_params[name] = desc

Expand Down Expand Up @@ -180,7 +187,8 @@ def add_function(self, function_id: str,
f'direction in function.json, but its annotation '
f'is azure.functions.Out in Python')

if param_has_anno and param_py_type in (str, bytes):
if param_has_anno and param_py_type in (str, bytes) and (
not bindings.has_implicit_output(desc.type)):
param_bind_type = 'generic'
else:
param_bind_type = desc.type
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,7 @@ def run(self):
],
extras_require={
'dev': [
'azure-functions==1.1.0',
'azure-functions==1.2.0b1',
'flake8~=3.7.9',
'mypy',
'pytest',
Expand Down