Skip to content

Commit d01677a

Browse files
authored
Correctness and documentation of the samples (#85)
* validated all samples except tensorflow * deleted non-samples, tested tensorflow sample, added types and comments * new readmes for fan-out-fan-in and function-chaining * renamed some functions so they are easier to reason about * disable aiohttp's input validation... potentially unsafe. ExternalEvents now shows no warnings!
1 parent 4cc93fa commit d01677a

File tree

55 files changed

+516
-3648
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

55 files changed

+516
-3648
lines changed

azure/durable_functions/models/utils/http_utils.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,11 @@ async def post_async_request(url: str, data: Any = None) -> [int, Any]:
2121
async with aiohttp.ClientSession() as session:
2222
async with session.post(url,
2323
json=data) as response:
24-
data = await response.json()
24+
# We disable aiohttp's input type validation
25+
# as the server may respond with alternative
26+
# data encodings. This is potentially unsafe.
27+
# More here: https://docs.aiohttp.org/en/stable/client_advanced.html
28+
data = await response.json(content_type=None)
2529
return [response.status, data]
2630

2731

host.json

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"version": "2.0",
3+
"extensionBundle": {
4+
"id": "Microsoft.Azure.Functions.ExtensionBundle",
5+
"version": "[1.*, 2.0.0)"
6+
}
7+
}

samples/durable_cli/setup.ps1

Lines changed: 0 additions & 48 deletions
This file was deleted.

samples/external_events/DurableOrchestrationTrigger/__init__.py renamed to samples/external_events/DurableOrchestration/__init__.py

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,30 @@
11
import json
22
import logging
3-
3+
from typing import List
44
import azure.durable_functions as df
55
import azure.functions as func
66

77

8-
def orchestrator_function(context: df.DurableOrchestrationContext):
8+
def orchestrator_function(context: df.DurableOrchestrationContext) -> List[str]:
9+
10+
"""This function provides the core function chaining orchestration logic
11+
12+
Parameters
13+
----------
14+
context: DurableOrchestrationContext
15+
This context has the past history and the durable orchestration API
16+
17+
Returns
18+
-------
19+
output: List[str]
20+
Returns an array of result by the activity functions.
21+
22+
Yields
23+
-------
24+
call_activity: str
25+
Yields, depending on the `json_rule`, to wait on either all
26+
tasks to complete, or until one of the tasks completes.
27+
"""
928

1029

1130
logging.debug("Creating the orchestrator function")

samples/external_events/DurableOrchestrationClient/__init__.py

Lines changed: 0 additions & 16 deletions
This file was deleted.
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
import logging
2+
3+
from azure.durable_functions import DurableOrchestrationClient
4+
import azure.functions as func
5+
6+
7+
async def main(req: func.HttpRequest, starter: str) -> func.HttpResponse:
8+
"""This function starts up the orchestrator from an HTTP endpoint
9+
10+
Parameters
11+
----------
12+
req: func.HttpRequest
13+
An HTTP Request object, it can be used to parse URL
14+
parameters.
15+
16+
starter: str
17+
A JSON-formatted string describing the orchestration context
18+
19+
Returns
20+
-------
21+
func.HttpResponse
22+
An HTTP response containing useful URLs for monitoring the
23+
status of newly generated orchestration instance
24+
"""
25+
26+
logging.debug("Recevied http request call with value {}".format(starter))
27+
function_name = req.route_params.get('functionName')
28+
client = DurableOrchestrationClient(starter)
29+
30+
logging.debug("About to call function {} asyncrounously".format(function_name))
31+
instance_id = await client.start_new(function_name, None, None)
32+
33+
return client.create_check_status_response(req, instance_id)
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,27 @@
1-
{
2-
"scriptFile": "__init__.py",
3-
"bindings": [
4-
{
5-
"authLevel": "function",
6-
"name": "req",
7-
"type": "httpTrigger",
8-
"direction": "in",
9-
"route": "orchestrators/{functionName}",
10-
"methods": [
11-
"post",
12-
"get"
13-
]
14-
},
15-
{
16-
"direction": "out",
17-
"name": "$return",
18-
"type": "http"
19-
},
20-
{
21-
"name": "starter",
22-
"type": "durableClient",
23-
"direction": "in",
24-
"datatype": "string"
25-
}
26-
]
27-
}
1+
{
2+
"scriptFile": "__init__.py",
3+
"bindings": [
4+
{
5+
"authLevel": "function",
6+
"name": "req",
7+
"type": "httpTrigger",
8+
"direction": "in",
9+
"route": "orchestrators/{functionName}",
10+
"methods": [
11+
"post",
12+
"get"
13+
]
14+
},
15+
{
16+
"direction": "out",
17+
"name": "$return",
18+
"type": "http"
19+
},
20+
{
21+
"name": "starter",
22+
"type": "orchestrationClient",
23+
"direction": "in",
24+
"datatype": "string"
25+
}
26+
]
27+
}

samples/external_events/RaiseEvent/__init__.py

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,23 @@
66

77

88
async def main(req: func.HttpRequest, starter: str) -> func.HttpResponse:
9+
"""Activity function to raise an external event to the orchestrator
10+
11+
Parameters
12+
----------
13+
req: func.HttpRequest
14+
An HTTP Request object, it can be used to parse URL
15+
parameters.
16+
17+
starter: str
18+
A JSON-formatted string describing the orchestration context
19+
20+
Returns
21+
-------
22+
func.HttpResponse
23+
HTTP response object whose body indicates which event
24+
was raised
25+
"""
926

1027
logging.info("Recevied http request to check startus {}".format(starter))
1128
client = DurableOrchestrationClient(starter)
@@ -16,5 +33,4 @@ async def main(req: func.HttpRequest, starter: str) -> func.HttpResponse:
1633
logging.info("Will check on event: {}".format(event_name))
1734

1835
await client.raise_event(instance_id, event_name, True)
19-
2036
return func.HttpResponse(f'"{event_name}" event is sent')
Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,26 @@
1-
{
2-
"scriptFile": "__init__.py",
3-
"bindings": [
4-
{
5-
"authLevel": "function",
6-
"name": "req",
7-
"type": "httpTrigger",
8-
"direction": "in",
9-
"methods": [
10-
"post",
11-
"get"
12-
]
13-
},
14-
{
15-
"name": "starter",
16-
"type": "durableClient",
17-
"direction": "in",
18-
"datatype": "string"
19-
},
20-
{
21-
"type": "http",
22-
"direction": "out",
23-
"name": "$return"
24-
}
25-
]
1+
{
2+
"scriptFile": "__init__.py",
3+
"bindings": [
4+
{
5+
"authLevel": "function",
6+
"name": "req",
7+
"type": "httpTrigger",
8+
"direction": "in",
9+
"methods": [
10+
"post",
11+
"get"
12+
]
13+
},
14+
{
15+
"name": "starter",
16+
"type": "orchestrationClient",
17+
"direction": "in",
18+
"datatype": "string"
19+
},
20+
{
21+
"type": "http",
22+
"direction": "out",
23+
"name": "$return"
24+
}
25+
]
2626
}

0 commit comments

Comments
 (0)