Skip to content

Correctness and documentation of the samples #85

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 6 commits into from
Mar 25, 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
6 changes: 5 additions & 1 deletion azure/durable_functions/models/utils/http_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,11 @@ async def post_async_request(url: str, data: Any = None) -> [int, Any]:
async with aiohttp.ClientSession() as session:
async with session.post(url,
json=data) as response:
data = await response.json()
# We disable aiohttp's input type validation
# as the server may respond with alternative
# data encodings. This is potentially unsafe.
# More here: https://docs.aiohttp.org/en/stable/client_advanced.html
data = await response.json(content_type=None)
return [response.status, data]


Expand Down
7 changes: 7 additions & 0 deletions host.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"version": "2.0",
"extensionBundle": {
"id": "Microsoft.Azure.Functions.ExtensionBundle",
"version": "[1.*, 2.0.0)"
}
}
48 changes: 0 additions & 48 deletions samples/durable_cli/setup.ps1

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,11 +1,30 @@
import json
import logging

from typing import List
import azure.durable_functions as df
import azure.functions as func


def orchestrator_function(context: df.DurableOrchestrationContext):
def orchestrator_function(context: df.DurableOrchestrationContext) -> List[str]:

"""This function provides the core function chaining orchestration logic

Parameters
----------
context: DurableOrchestrationContext
This context has the past history and the durable orchestration API

Returns
-------
output: List[str]
Returns an array of result by the activity functions.

Yields
-------
call_activity: str
Yields, depending on the `json_rule`, to wait on either all
tasks to complete, or until one of the tasks completes.
"""


logging.debug("Creating the orchestrator function")
Expand Down
16 changes: 0 additions & 16 deletions samples/external_events/DurableOrchestrationClient/__init__.py

This file was deleted.

33 changes: 33 additions & 0 deletions samples/external_events/DurableTrigger/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import logging

from azure.durable_functions import DurableOrchestrationClient
import azure.functions as func


async def main(req: func.HttpRequest, starter: str) -> func.HttpResponse:
"""This function starts up the orchestrator from an HTTP endpoint

Parameters
----------
req: func.HttpRequest
An HTTP Request object, it can be used to parse URL
parameters.

starter: str
A JSON-formatted string describing the orchestration context

Returns
-------
func.HttpResponse
An HTTP response containing useful URLs for monitoring the
status of newly generated orchestration instance
"""

logging.debug("Recevied http request call with value {}".format(starter))
function_name = req.route_params.get('functionName')
client = DurableOrchestrationClient(starter)

logging.debug("About to call function {} asyncrounously".format(function_name))
instance_id = await client.start_new(function_name, None, None)

return client.create_check_status_response(req, instance_id)
Original file line number Diff line number Diff line change
@@ -1,27 +1,27 @@
{
"scriptFile": "__init__.py",
"bindings": [
{
"authLevel": "function",
"name": "req",
"type": "httpTrigger",
"direction": "in",
"route": "orchestrators/{functionName}",
"methods": [
"post",
"get"
]
},
{
"direction": "out",
"name": "$return",
"type": "http"
},
{
"name": "starter",
"type": "durableClient",
"direction": "in",
"datatype": "string"
}
]
}
{
"scriptFile": "__init__.py",
"bindings": [
{
"authLevel": "function",
"name": "req",
"type": "httpTrigger",
"direction": "in",
"route": "orchestrators/{functionName}",
"methods": [
"post",
"get"
]
},
{
"direction": "out",
"name": "$return",
"type": "http"
},
{
"name": "starter",
"type": "orchestrationClient",
"direction": "in",
"datatype": "string"
}
]
}
18 changes: 17 additions & 1 deletion samples/external_events/RaiseEvent/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,23 @@


async def main(req: func.HttpRequest, starter: str) -> func.HttpResponse:
"""Activity function to raise an external event to the orchestrator

Parameters
----------
req: func.HttpRequest
An HTTP Request object, it can be used to parse URL
parameters.

starter: str
A JSON-formatted string describing the orchestration context

Returns
-------
func.HttpResponse
HTTP response object whose body indicates which event
was raised
"""

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

await client.raise_event(instance_id, event_name, True)

return func.HttpResponse(f'"{event_name}" event is sent')
50 changes: 25 additions & 25 deletions samples/external_events/RaiseEvent/function.json
Original file line number Diff line number Diff line change
@@ -1,26 +1,26 @@
{
"scriptFile": "__init__.py",
"bindings": [
{
"authLevel": "function",
"name": "req",
"type": "httpTrigger",
"direction": "in",
"methods": [
"post",
"get"
]
},
{
"name": "starter",
"type": "durableClient",
"direction": "in",
"datatype": "string"
},
{
"type": "http",
"direction": "out",
"name": "$return"
}
]
{
"scriptFile": "__init__.py",
"bindings": [
{
"authLevel": "function",
"name": "req",
"type": "httpTrigger",
"direction": "in",
"methods": [
"post",
"get"
]
},
{
"name": "starter",
"type": "orchestrationClient",
"direction": "in",
"datatype": "string"
},
{
"type": "http",
"direction": "out",
"name": "$return"
}
]
}
14 changes: 13 additions & 1 deletion samples/external_events/SuccessActions/__init__.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,20 @@
import logging
import json


def main(args: str) -> str:
"""Activity function to raise an external event to the orchestrator

Parameters
----------
req: func.HttpRequest
An HTTP Request object, it can be used to parse URL
parameters.

Returns
-------
str
A 'Hello-string' to the argument passed in via args
"""
logging.info(f"Activity Triggered: SuccessActions")

args= json.loads(args)
Expand Down
11 changes: 0 additions & 11 deletions samples/external_events/extensions.csproj

This file was deleted.

6 changes: 5 additions & 1 deletion samples/external_events/host.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
{
"version": "2.0"
"version": "2.0",
"extensionBundle": {
"id": "Microsoft.Azure.Functions.ExtensionBundle",
"version": "[1.*, 2.0.0)"
}
}
42 changes: 29 additions & 13 deletions samples/fan_out_fan_in/DurableTrigger/__init__.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,29 @@
import logging

from azure.durable_functions import DurableOrchestrationClient
import azure.functions as func


def main(req: func.HttpRequest, starter: str, message):
function_name = req.route_params.get('functionName')
logging.info(starter)
client = DurableOrchestrationClient(starter)
client.start_new(function_name, None, None)
response = func.HttpResponse(status_code=200, body=starter)
message.set(response)
import logging

from azure.durable_functions import DurableOrchestrationClient
import azure.functions as func


async def main(req: func.HttpRequest, starter: str, message):
"""This function starts up the orchestrator from an HTTP endpoint

Parameters
----------
req: func.HttpRequest
An HTTP Request object, it can be used to parse URL
parameters.

starter: str
A JSON-formatted string describing the orchestration context

message:
An azure functions http output binding, it enables us to establish
an http response.
"""

function_name = req.route_params.get('functionName')
logging.info(starter)
client = DurableOrchestrationClient(starter)
instance_id = await client.start_new(function_name, None, None)
response = client.create_check_status_response(req, instance_id)
message.set(response)
Loading