66import os
77import threading
88import time
9- from collections import namedtuple
9+ from collections . abc import Generator
1010from dataclasses import dataclass
1111from datetime import timedelta
12+ from typing import Any , NamedTuple
1213
1314from azure .identity import DefaultAzureCredential
1415
1718from durabletask .azuremanaged .worker import DurableTaskSchedulerWorker
1819
1920
21+ class Approval (NamedTuple ):
22+ """Represents an approval event payload"""
23+ approver : str
24+
25+
2026@dataclass
2127class Order :
2228 """Represents a purchase order"""
@@ -39,7 +45,7 @@ def place_order(_: task.ActivityContext, order: Order) -> None:
3945 print (f'*** Placing order: { order } ' )
4046
4147
42- def purchase_order_workflow (ctx : task .OrchestrationContext , order : Order ):
48+ def purchase_order_workflow (ctx : task .OrchestrationContext , order : Order ) -> Generator [ task . Task [ Any ], Any , str ] :
4349 """Orchestrator function that represents a purchase order workflow"""
4450 # Orders under $1000 are auto-approved
4551 if order .Cost < 1000 :
@@ -87,7 +93,7 @@ def purchase_order_workflow(ctx: task.OrchestrationContext, order: Order):
8793
8894 def prompt_for_approval ():
8995 input ("Press [ENTER] to approve the order...\n " )
90- approval_event = namedtuple ( " Approval" , [ "approver" ]) (args .approver )
96+ approval_event = Approval (args .approver )
9197 c .raise_orchestration_event (instance_id , "approval_received" , data = approval_event )
9298
9399 # Prompt the user for approval on a background thread
@@ -133,7 +139,7 @@ def prompt_for_approval():
133139
134140 def prompt_for_approval ():
135141 input ("Press [ENTER] to approve the order...\n " )
136- approval_event = namedtuple ( " Approval" , [ "approver" ]) (args .approver )
142+ approval_event = Approval (args .approver )
137143 c .raise_orchestration_event (instance_id , "approval_received" , data = approval_event )
138144
139145 # Prompt the user for approval on a background thread
0 commit comments