Skip to content

Commit 9da6036

Browse files
author
Hanzhang Zeng (Roger)
committed
Fix samples to use the latest func.OrchestrationContext annotation
1 parent f1460c3 commit 9da6036

File tree

12 files changed

+47
-51
lines changed

12 files changed

+47
-51
lines changed

samples/external_events/DurableOrchestrationTrigger/__init__.py

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import logging
22
import azure.durable_functions as df
3+
import azure.functions as func
34
import json
45

56
def generator_function(context):
@@ -22,12 +23,12 @@ def generator_function(context):
2223
tasks = []
2324
for event in json_rule["condition"]["wait_events"]:
2425
tasks.append(context.wait_for_external_event(event))
25-
26+
2627
if json_rule["condition"]["logic"] == 'and':
2728
yield context.task_all(tasks)
28-
elif json_rule["condition"]["logic"] == 'or':
29+
elif json_rule["condition"]["logic"] == 'or':
2930
yield context.task_any(tasks)
30-
31+
3132
output = []
3233
for action in json_rule["satisfied"]:
3334
result = yield context.call_activity(action["activity_func_name"], json.dumps(action["args"]))
@@ -36,17 +37,17 @@ def generator_function(context):
3637
return output
3738

3839

39-
def main(context: str):
40+
def main(context: func.OrchestrationContext):
4041
"""This function creates the orchestration and provides
4142
the durable framework with the core orchestration logic
42-
43+
4344
Arguments:
44-
context {str} -- Function context containing the orchestration API's
45+
context {str} -- Function context containing the orchestration API's
4546
and current context of the long running workflow.
46-
47+
4748
Returns:
4849
OrchestratorState - State of current orchestration
4950
"""
5051
orchestrate = df.Orchestrator.create(generator_function)
51-
result = orchestrate(context)
52+
result = orchestrate(context.body)
5253
return result

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+
}
Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,21 @@
11
import json
2+
import azure.functions as func
23
import azure.durable_functions as df
34

4-
55
def generator_function(context):
66
activity_count = yield context.call_activity("GetActivityCount", 5)
77
activity_list = json.loads(activity_count)
88

99
tasks = [context.call_activity("ParrotValue", i) for i in activity_list]
10-
10+
1111
tasks_result = yield context.task_all(tasks)
1212
values = [int(t) for t in tasks_result]
1313
message = yield context.call_activity("ShowMeTheSum", values)
1414

1515
return message
1616

1717

18-
def main(context: str):
18+
def main(context: func.OrchestrationContext):
1919
orchestrate = df.Orchestrator.create(generator_function)
20-
21-
result = orchestrate(context)
22-
20+
result = orchestrate(context.body)
2321
return result

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

samples/fan_out_fan_in_tensorflow/FanOutFanIn/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
def _get_classify_images_tasks(config, image_list, context):
66
"""Get list of tasks that breaks down the execution of the predications.
77
8-
will create a list of tasks to perform that is split evenly across the
8+
will create a list of tasks to perform that is split evenly across the
99
different instances
1010
1111
Arguments:
@@ -38,7 +38,7 @@ def _get_classify_images_tasks(config, image_list, context):
3838
def generator_function(context):
3939
"""Get the generator that will need to be orchestrated by durable functions.
4040
41-
This function will get a list of images to do a prediction of, fan out the
41+
This function will get a list of images to do a prediction of, fan out the
4242
prediction tasks then summarize the results
4343
4444
Arguments:

samples/fan_out_fan_in_tensorflow/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: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,47 +1,50 @@
11
import logging
2+
import azure.functions as func
23
import azure.durable_functions as df
34

45
def generator_function(context):
56
"""This function provides the core function chaining orchestration logic
6-
7+
78
Parameters
89
----------
910
context : DurableOrchestrationContext
10-
This context has the past history
11+
This context has the past history
1112
and the durable orchestration API's to chain a set of functions
12-
13+
1314
Returns
1415
-------
1516
final_result: str
1617
Returns the final result after the chain completes
17-
18+
1819
Yields
1920
-------
2021
call_activity: str
2122
Yields at every step of the function chain orchestration logic
2223
"""
2324

24-
# Chained functions - output of a function is passed as
25+
# Chained functions - output of a function is passed as
2526
# input to the next function in the chain
2627
r1 = yield context.call_activity("DurableActivity", "One")
2728
r2 = yield context.call_activity("DurableActivity", r1)
2829
final_result = yield context.call_activity("DurableActivity", r2)
2930

3031
return final_result
3132

32-
def main(context:str):
33+
def main(context: func.OrchestrationContext):
3334
"""This function creates the orchestration and provides
3435
the durable framework with the core orchestration logic
35-
36+
3637
Parameters
3738
----------
3839
context : str
39-
Function context containing the orchestration API's
40+
Function context containing the orchestration API's
4041
and current context of the long running workflow.
41-
42+
4243
Returns:
4344
OrchestratorState - State of currently running orchestration
4445
"""
4546
orchestrate = df.Orchestrator.create(generator_function)
46-
result = orchestrate(context)
47-
return result
47+
48+
result = orchestrate(context.body)
49+
50+
return result

samples/function_chaining/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/python_durable_bindings/DurableFanoutOrchestrationTrigger/__init__.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import logging
2-
2+
import azure.functions as func
33
import azure.durable_functions as df
44

55

@@ -15,11 +15,11 @@ def generator_function(context):
1515
return results
1616

1717

18-
def main(context: str):
19-
logging.warning("Durable Orchestration Trigger: " + context)
18+
def main(context: func.OrchestrationContext):
19+
logging.warning(f"Durable Orchestration Trigger: {context}")
2020
orchestrate = df.Orchestrator.create(generator_function)
2121
logging.warning("!!!type(orchestrate) " + str(type(orchestrate)))
22-
result = orchestrate(context)
22+
result = orchestrate(context.body)
2323
logging.warning("!!!serialized json : " + result)
2424
logging.warning("!!!type(result) " + str(type(result)))
2525
return result

samples/python_durable_bindings/DurableFanoutOrchestrationTrigger/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+
}

0 commit comments

Comments
 (0)