1+ import logging
2+ import azure .functions as func
3+ import azure .durable_functions as df
4+
5+ myApp = df .DFApp (http_auth_level = func .AuthLevel .ANONYMOUS )
6+
7+ @myApp .route (route = "orchestrators/{functionName}" )
8+ @myApp .durable_client_input (client_name = "client" )
9+ async def http_start (req : func .HttpRequest , client ):
10+ function_name = req .route_params .get ('functionName' )
11+ instance_id = await client .start_new (function_name )
12+
13+ logging .info (f"Started orchestration with ID = '{ instance_id } '." )
14+ return client .create_check_status_response (req , instance_id )
15+
16+ @myApp .orchestration_trigger (context_name = "context" )
17+ def my_orchestrator (context : df .DurableOrchestrationContext ):
18+ if (context .version == "1.0" ):
19+ # Legacy code path
20+ activity_result = yield context .call_activity ('say_hello' , "v1.0" )
21+ else :
22+ # New code path
23+ activity_result = yield context .call_activity ('say_hello' , "v2.0" )
24+
25+ """
26+ While the orchestration is waiting for the external event,
27+ stop the app, update the defaultVersion in host.json to "2.0",
28+ then restart the app and send a "Continue" event.
29+ This orchestration instance should continue with the old version.
30+ """
31+ context .set_custom_status ("Waiting for Continue event..." )
32+ yield context .wait_for_external_event ("Continue" )
33+ context .set_custom_status ("Continue event received" )
34+
35+ """
36+ New orchestration instances (including sub-orchestrations)
37+ will use the current defaultVersion specified in host.json.
38+ """
39+ sub_result = yield context .call_sub_orchestrator ('my_sub_orchestrator' )
40+ return [f'Orchestration version: { context .version } ' , f'Suborchestration version: { sub_result } ' , activity_result ]
41+
42+ @myApp .orchestration_trigger (context_name = "context" )
43+ def my_sub_orchestrator (context : df .DurableOrchestrationContext ):
44+ return context .version
45+
46+ @myApp .activity_trigger (input_name = "city" )
47+ def say_hello (city : str ) -> str :
48+ return f"Hello { city } !"
0 commit comments