Skip to content

Commit 96216bb

Browse files
author
Hanzhang Zeng (Roger)
committed
Use new syntax to replace main endpoint
1 parent 64e69e4 commit 96216bb

File tree

12 files changed

+320
-68
lines changed

12 files changed

+320
-68
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+
}

samples/external_events/DurableOrchestrationTrigger/__init__.py

Lines changed: 6 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
1+
import json
12
import logging
3+
24
import azure.durable_functions as df
35
import azure.functions as func
4-
import json
56

6-
def generator_function(context):
77

8-
json_rule={
8+
def orchestrator_function(context: df.DurableOrchestrationContext):
9+
10+
json_rule = {
911
"condition": {
1012
"wait_events": ["A","B"],
1113
"logic": "and"
@@ -37,17 +39,4 @@ def generator_function(context):
3739
return output
3840

3941

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

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: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
import json
2+
23
import azure.functions as func
34
import azure.durable_functions as df
45

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

@@ -15,7 +17,4 @@ def generator_function(context):
1517
return message
1618

1719

18-
def main(context: func.OrchestrationContext):
19-
orchestrate = df.Orchestrator.create(generator_function)
20-
result = orchestrate(context.body)
21-
return result
20+
main = df.Orchestrator.create(orchestrator_function)
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)

samples/fan_out_fan_in_tensorflow/FanOutFanIn/__init__.py

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
import json
2+
3+
import azure.functions as func
24
import azure.durable_functions as df
35

46

@@ -35,7 +37,7 @@ def _get_classify_images_tasks(config, image_list, context):
3537
return tasks
3638

3739

38-
def generator_function(context):
40+
def orchestrator_function(context: df.DurableOrchestrationContext):
3941
"""Get the generator that will need to be orchestrated by durable functions.
4042
4143
This function will get a list of images to do a prediction of, fan out the
@@ -74,9 +76,4 @@ def generator_function(context):
7476
return summary
7577

7678

77-
def main(context: str):
78-
orchestrate = df.Orchestrator.create(generator_function)
79-
80-
result = orchestrate(context)
81-
82-
return result
79+
main = df.Orchestrator.create(orchestrator_function)
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
<PropertyGroup>
3+
<TargetFramework>netstandard2.0</TargetFramework>
4+
<WarningsAsErrors></WarningsAsErrors>
5+
<DefaultItemExcludes>**</DefaultItemExcludes>
6+
</PropertyGroup>
7+
<ItemGroup>
8+
<PackageReference Include="Microsoft.Azure.WebJobs.Extensions.DurableTask" Version="2.1.1" />
9+
<PackageReference Include="Microsoft.Azure.WebJobs.Script.ExtensionsMetadataGenerator" Version="1.1.0" />
10+
</ItemGroup>
11+
</Project>

0 commit comments

Comments
 (0)