Skip to content

Demo sample for function chaining #20

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 4 commits into from
Jan 21, 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
1 change: 0 additions & 1 deletion azure/durable_functions/tasks/task_utilities.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import logging
import json

from ..models.history import HistoryEventType


Expand Down
5 changes: 5 additions & 0 deletions samples/function_chaining/DurableActivity/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import logging

def main(name: str) -> str:
logging.warning(f"Activity Triggered: {name}")
return f'Hello Activity: {name}!'
12 changes: 12 additions & 0 deletions samples/function_chaining/DurableActivity/function.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"scriptFile": "__init__.py",
"bindings": [
{
"name": "name",
"type": "activityTrigger",
"direction": "in",
"datatype": "string"
}
],
"disabled": false
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import logging
import azure.durable_functions as df


def generator_function(context):
"""This function provides the core function chaining orchestration logic

Arguments:
context {DurableOrchestrationContext} -- This context has the past history
and the durable orchestration API's to chain a set of functions

Returns:
final_result {str} -- Returns the final result after the chain completes

Yields:
call_activity {str} -- Yields at every step of the function chain orchestration logic
"""
outputs = []

r1 = yield context.df.call_activity("DurableActivity", "One")
r2 = yield context.df.call_activity("DurableActivity", r1)
final_result = yield context.df.call_activity("DurableActivity", r2)

return final_result


def main(context: str):
"""This function creates the orchestration and provides
the durable framework with the core orchestration logic

Arguments:
context {str} -- Function context containing the orchestration API's
and current context of the long running workflow.

Returns:
OrchestratorState - State of current orchestration
"""
orchestrate = df.Orchestrator.create(generator_function)
result = orchestrate(context)
return result
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"scriptFile": "__init__.py",
"bindings": [
{
"name": "context",
"type": "orchestrationTrigger",
"direction": "in",
"dataType": "string"
}
],
"disabled": false
}
11 changes: 11 additions & 0 deletions samples/function_chaining/extensions.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
<WarningsAsErrors></WarningsAsErrors>
<DefaultItemExcludes>**</DefaultItemExcludes>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.Azure.WebJobs.Extensions.DurableTask" Version="2.1.1" />
<PackageReference Include="Microsoft.Azure.WebJobs.Script.ExtensionsMetadataGenerator" Version="1.0.2" />
</ItemGroup>
</Project>
3 changes: 3 additions & 0 deletions samples/function_chaining/host.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"version": "2.0"
}
37 changes: 37 additions & 0 deletions scripts/sample_deploy.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
#!/bin/bash

echo "Checking for prerequisites..."
if ! type npm > /dev/null; then
echo "Prerequisite Check 1: Install Node.js and NPM"
exit 1
fi

if ! type dotnet > /dev/null; then
echo "Prerequisite Check 2: Install .NET Core 2.1 SDK or Runtime"
exit 1
fi

if ! type func > /dev/null; then
echo "Prerequisite Check 3: Install Azure Functions Core Tools"
exit 1
fi

echo "Pre-requisites satisfied..."

echo "Creating sample folders..."
DIRECTORY=/tmp/df_test
if [ ! -d "$DIRECTORY" ]; then
mkdir /tmp/df_test
else
rm -rf /tmp/df_test/*
fi

SAMPLE=function_chaining
cp -r ../samples/$SAMPLE $DIRECTORY/
cd $DIRECTORY/$SAMPLE
python -m venv env
source env/bin/activate
pip install /Users/prananth/azure-functions-durable-python
func init .
func extensions install
echo "Done"