1313from datetime import timedelta
1414from time import sleep
1515from dapr .ext .workflow import (
16+ DaprWorkflowClient ,
1617 WorkflowRuntime ,
1718 DaprWorkflowContext ,
1819 WorkflowActivityContext ,
@@ -106,7 +107,7 @@ def act_for_child_wf(ctx: WorkflowActivityContext, inp):
106107
107108
108109def main ():
109- with DaprClient () as d :
110+ with DaprWorkflowClient () as wfc :
110111 workflow_runtime = WorkflowRuntime ()
111112 workflow_runtime .register_workflow (hello_world_wf )
112113 workflow_runtime .register_workflow (child_retryable_wf )
@@ -119,14 +120,11 @@ def main():
119120 sleep (2 )
120121
121122 print ('==========Start Counter Increase as per Input:==========' )
122- start_resp = d . start_workflow (
123+ instance_id = wfc . schedule_new_workflow (
123124 instance_id = instance_id ,
124- workflow_component = workflow_component ,
125- workflow_name = workflow_name ,
126- input = input_data ,
127- workflow_options = workflow_options ,
128- )
129- print (f'start_resp { start_resp .instance_id } ' )
125+ workflow = hello_world_wf ,
126+ input = input_data )
127+ print (f'start_resp { instance_id } ' )
130128
131129 # Sleep for a while to let the workflow run
132130 sleep (12 )
@@ -135,75 +133,70 @@ def main():
135133 assert child_orchestrator_string == '1aa2bb3cc'
136134
137135 # Pause Test
138- d .pause_workflow (instance_id = instance_id , workflow_component = workflow_component )
139- get_response = d .get_workflow (
140- instance_id = instance_id , workflow_component = workflow_component
141- )
136+ wfc .pause_workflow (instance_id = instance_id )
137+ get_response = wfc .get_workflow_state (instance_id = instance_id , fetch_payloads = True )
142138 print (f'Get response from { workflow_name } after pause call: { get_response .runtime_status } ' )
143139
144140 # Resume Test
145- d .resume_workflow (instance_id = instance_id , workflow_component = workflow_component )
146- get_response = d .get_workflow (
147- instance_id = instance_id , workflow_component = workflow_component
148- )
141+ wfc .resume_workflow (instance_id = instance_id )
142+ get_response = wfc .get_workflow_state (instance_id = instance_id , fetch_payloads = True )
149143 print (f'Get response from { workflow_name } after resume call: { get_response .runtime_status } ' )
150144
151145 sleep (1 )
152146 # Raise event
153- d .raise_workflow_event (
154- instance_id = child_instance_id ,
155- workflow_component = workflow_component ,
147+ wfc .raise_workflow_event (
148+ instance_id = instance_id ,
156149 event_name = event_name ,
157- event_data = event_data ,
150+ data = event_data ,
158151 )
159152
160153 sleep (5 )
161154 # Purge Test
162- d .purge_workflow (instance_id = instance_id , workflow_component = workflow_component )
155+ # // TODO IMPLEMENT PURGE
156+ # d.purge_workflow(instance_id=instance_id, workflow_component=workflow_component)
163157 try :
164- d .get_workflow (instance_id = instance_id , workflow_component = workflow_component )
165- except DaprInternalError as err :
158+ wfc .get_workflow_state (instance_id = instance_id , fetch_payloads = True )
159+ except Exception as err :
160+ # TODO temporary print
161+ print (f'got error { err } ' )
166162 if non_existent_id_error in err ._message :
167163 print ('Instance Successfully Purged' )
168164
169165 # Kick off another workflow for termination purposes
170166 # This will also test using the same instance ID on a new workflow after
171167 # the old instance was purged
172- start_resp = d . start_workflow (
168+ instance_id = wfc . schedule_new_workflow (
173169 instance_id = instance_id ,
174- workflow_component = workflow_component ,
175- workflow_name = workflow_name ,
176- input = input_data ,
177- workflow_options = workflow_options ,
170+ workflow = hello_world_wf ,
171+ input = input_data
178172 )
179- print (f'start_resp { start_resp . instance_id } ' )
173+ print (f'start_resp { instance_id } ' )
180174
181175 sleep (5 )
182176 # Terminate Test
183- d .terminate_workflow (instance_id = instance_id , workflow_component = workflow_component )
177+ wfc .terminate_workflow (instance_id = instance_id )
184178 sleep (1 )
185- get_response = d .get_workflow (
186- instance_id = instance_id , workflow_component = workflow_component
187- )
179+ get_response = wfc .get_workflow_state (instance_id = instance_id , fetch_payloads = True )
188180 print (
189181 f'Get response from { workflow_name } '
190182 f'after terminate call: { get_response .runtime_status } '
191183 )
192- child_get_response = d . get_workflow (
193- instance_id = child_instance_id , workflow_component = workflow_component
184+ child_get_response = wfc . get_workflow_state (
185+ instance_id = child_instance_id , fetch_payloads = True
194186 )
195187 print (
196188 f'Get response from { child_workflow_name } '
197189 f'after terminate call: { child_get_response .runtime_status } '
198190 )
199191
200192 # Purge Test
201- d .purge_workflow (instance_id = instance_id , workflow_component = workflow_component )
202- try :
203- d .get_workflow (instance_id = instance_id , workflow_component = workflow_component )
204- except DaprInternalError as err :
205- if non_existent_id_error in err ._message :
206- print ('Instance Successfully Purged' )
193+ # TODO IMPLEMENT PURGE
194+ # d.purge_workflow(instance_id=instance_id, workflow_component=workflow_component)
195+ # try:
196+ # d.get_workflow(instance_id=instance_id, workflow_component=workflow_component)
197+ # except DaprInternalError as err:
198+ # if non_existent_id_error in err._message:
199+ # print('Instance Successfully Purged')
207200
208201 workflow_runtime .shutdown ()
209202
0 commit comments