Skip to content

Commit 2eee61e

Browse files
author
Hanzhang Zeng (Roger)
committed
# This is a combination of 3 commits.
Fix samples to use the latest func.OrchestrationContext annotation Use new syntax to replace main endpoint Fix old python_durable_bindings samples
1 parent de04569 commit 2eee61e

File tree

29 files changed

+494
-2062
lines changed

29 files changed

+494
-2062
lines changed

samples/external_events/.gitignore

Lines changed: 133 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,133 @@
1+
# Byte-compiled / optimized / DLL files
2+
__pycache__/
3+
*.py[cod]
4+
*$py.class
5+
6+
# C extensions
7+
*.so
8+
9+
# Distribution / packaging
10+
.Python
11+
build/
12+
develop-eggs/
13+
dist/
14+
downloads/
15+
eggs/
16+
.eggs/
17+
lib/
18+
lib64/
19+
parts/
20+
sdist/
21+
var/
22+
wheels/
23+
pip-wheel-metadata/
24+
share/python-wheels/
25+
*.egg-info/
26+
.installed.cfg
27+
*.egg
28+
MANIFEST
29+
30+
# PyInstaller
31+
# Usually these files are written by a python script from a template
32+
# before PyInstaller builds the exe, so as to inject date/other infos into it.
33+
*.manifest
34+
*.spec
35+
36+
# Installer logs
37+
pip-log.txt
38+
pip-delete-this-directory.txt
39+
40+
# Unit test / coverage reports
41+
htmlcov/
42+
.tox/
43+
.nox/
44+
.coverage
45+
.coverage.*
46+
.cache
47+
nosetests.xml
48+
coverage.xml
49+
*.cover
50+
.hypothesis/
51+
.pytest_cache/
52+
53+
# Translations
54+
*.mo
55+
*.pot
56+
57+
# Django stuff:
58+
*.log
59+
local_settings.py
60+
db.sqlite3
61+
62+
# Flask stuff:
63+
instance/
64+
.webassets-cache
65+
66+
# Scrapy stuff:
67+
.scrapy
68+
69+
# Sphinx documentation
70+
docs/_build/
71+
72+
# PyBuilder
73+
target/
74+
75+
# Jupyter Notebook
76+
.ipynb_checkpoints
77+
78+
# IPython
79+
profile_default/
80+
ipython_config.py
81+
82+
# pyenv
83+
.python-version
84+
85+
# pipenv
86+
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
87+
# However, in case of collaboration, if having platform-specific dependencies or dependencies
88+
# having no cross-platform support, pipenv may install dependencies that don’t work, or not
89+
# install all needed dependencies.
90+
#Pipfile.lock
91+
92+
# celery beat schedule file
93+
celerybeat-schedule
94+
95+
# SageMath parsed files
96+
*.sage.py
97+
98+
# Environments
99+
.env
100+
.venv
101+
env/
102+
venv/
103+
ENV/
104+
env.bak/
105+
venv.bak/
106+
107+
# Spyder project settings
108+
.spyderproject
109+
.spyproject
110+
111+
# Rope project settings
112+
.ropeproject
113+
114+
# mkdocs documentation
115+
/site
116+
117+
# mypy
118+
.mypy_cache/
119+
.dmypy.json
120+
dmypy.json
121+
122+
# Pyre type checker
123+
.pyre/
124+
125+
# Azure Functions artifacts
126+
bin
127+
obj
128+
appsettings.json
129+
local.settings.json
130+
.python_packages
131+
132+
# pycharm
133+
.idea

samples/external_events/DurableOrchestrationClient/__init__.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import logging
2-
import azure.functions as func
2+
33
from azure.durable_functions import DurableOrchestrationClient
4+
import azure.functions as func
45

56

67
async def main(req: func.HttpRequest, starter: str):

samples/external_events/DurableOrchestrationClient/function.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
},
1515
{
1616
"direction": "out",
17-
"name": "$return",
17+
"name": "$return",
1818
"type": "http"
1919
},
2020
{
@@ -24,4 +24,4 @@
2424
"datatype": "string"
2525
}
2626
]
27-
}
27+
}
Lines changed: 10 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
1+
import json
12
import logging
3+
24
import azure.durable_functions as df
3-
import json
5+
import azure.functions as func
46

5-
def generator_function(context):
67

7-
json_rule={
8+
def orchestrator_function(context: df.DurableOrchestrationContext):
9+
10+
json_rule = {
811
"condition": {
912
"wait_events": ["A","B"],
1013
"logic": "and"
@@ -22,12 +25,12 @@ def generator_function(context):
2225
tasks = []
2326
for event in json_rule["condition"]["wait_events"]:
2427
tasks.append(context.wait_for_external_event(event))
25-
28+
2629
if json_rule["condition"]["logic"] == 'and':
2730
yield context.task_all(tasks)
28-
elif json_rule["condition"]["logic"] == 'or':
31+
elif json_rule["condition"]["logic"] == 'or':
2932
yield context.task_any(tasks)
30-
33+
3134
output = []
3235
for action in json_rule["satisfied"]:
3336
result = yield context.call_activity(action["activity_func_name"], json.dumps(action["args"]))
@@ -36,17 +39,4 @@ def generator_function(context):
3639
return output
3740

3841

39-
def main(context: str):
40-
"""This function creates the orchestration and provides
41-
the durable framework with the core orchestration logic
42-
43-
Arguments:
44-
context {str} -- Function context containing the orchestration API's
45-
and current context of the long running workflow.
46-
47-
Returns:
48-
OrchestratorState - State of current orchestration
49-
"""
50-
orchestrate = df.Orchestrator.create(generator_function)
51-
result = orchestrate(context)
52-
return result
42+
main = df.Orchestrator.create(orchestrator_function)

samples/external_events/DurableOrchestrationTrigger/function.json

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,8 @@
44
{
55
"name": "context",
66
"type": "orchestrationTrigger",
7-
"direction": "in",
8-
"dataType": "string"
7+
"direction": "in"
98
}
109
],
1110
"disabled": false
12-
}
11+
}

samples/external_events/RaiseEvent/__init__.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1-
import logging
2-
import azure.functions as func
31
import json
2+
import logging
3+
44
from azure.durable_functions import DurableOrchestrationClient
5+
import azure.functions as func
56

67

78
async def main(req: func.HttpRequest, starter: str) -> func.HttpResponse:
Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
1-
import logging
2-
import azure.functions as func
1+
import logging
2+
33
from azure.durable_functions import DurableOrchestrationClient
4+
import azure.functions as func
45

56

67
def main(req: func.HttpRequest, starter: str, message):
7-
function_name = req.route_params.get('functionName')
8-
logging.info(starter)
9-
client = DurableOrchestrationClient(starter)
10-
client.start_new(function_name, None, None)
11-
response = func.HttpResponse(status_code=200, body=starter)
12-
message.set(response)
8+
function_name = req.route_params.get('functionName')
9+
logging.info(starter)
10+
client = DurableOrchestrationClient(starter)
11+
client.start_new(function_name, None, None)
12+
response = func.HttpResponse(status_code=200, body=starter)
13+
message.set(response)
Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,20 @@
11
import json
2+
3+
import azure.functions as func
24
import azure.durable_functions as df
35

46

5-
def generator_function(context):
7+
def orchestrator_function(context: df.DurableOrchestrationContext):
68
activity_count = yield context.call_activity("GetActivityCount", 5)
79
activity_list = json.loads(activity_count)
810

911
tasks = [context.call_activity("ParrotValue", i) for i in activity_list]
10-
12+
1113
tasks_result = yield context.task_all(tasks)
1214
values = [int(t) for t in tasks_result]
1315
message = yield context.call_activity("ShowMeTheSum", values)
1416

1517
return message
1618

1719

18-
def main(context: str):
19-
orchestrate = df.Orchestrator.create(generator_function)
20-
21-
result = orchestrate(context)
22-
23-
return result
20+
main = df.Orchestrator.create(orchestrator_function)

samples/fan_out_fan_in/FanOutFanIn/function.json

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,8 @@
44
{
55
"name": "context",
66
"type": "orchestrationTrigger",
7-
"direction": "in",
8-
"dataType": "string"
7+
"direction": "in"
98
}
109
],
1110
"disabled": false
12-
}
11+
}
Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
1-
import logging
2-
import azure.functions as func
1+
import logging
2+
33
from azure.durable_functions import DurableOrchestrationClient
4+
import azure.functions as func
45

56

67
def main(req: func.HttpRequest, starter: str, message):
7-
function_name = req.route_params.get('functionName')
8-
logging.info(starter)
9-
client = DurableOrchestrationClient(starter)
10-
client.start_new(function_name, None, None)
11-
response = func.HttpResponse(status_code=200, body=starter)
12-
message.set(response)
8+
function_name = req.route_params.get('functionName')
9+
logging.info(starter)
10+
client = DurableOrchestrationClient(starter)
11+
client.start_new(function_name, None, None)
12+
response = func.HttpResponse(status_code=200, body=starter)
13+
message.set(response)

0 commit comments

Comments
 (0)