@@ -852,6 +852,16 @@ def wait_for_external_event(self, name: str) -> task.Task:
852852 task_list .append (external_event_task )
853853 return external_event_task
854854
855+ def send_event (self , instance_id : str , event_name : str , * ,
856+ data : Optional [Any ] = None ) -> task .Task :
857+ id = self .next_sequence_number ()
858+ encoded_data = shared .to_json (data ) if data is not None else None
859+ action = ph .new_send_event_action (id , instance_id , event_name , encoded_data )
860+ self ._pending_actions [id ] = action
861+ send_event_task = task .CompletableTask ()
862+ self ._pending_tasks [id ] = send_event_task
863+ return send_event_task
864+
855865 def continue_as_new (self , new_input , * , save_events : bool = False ) -> None :
856866 if self ._is_complete :
857867 return
@@ -1188,6 +1198,17 @@ def process_event(
11881198 self ._logger .info (
11891199 f"{ ctx .instance_id } : Event '{ event_name } ' has been buffered as there are no tasks waiting for it."
11901200 )
1201+ elif event .HasField ("eventSent" ):
1202+ # This history event confirms that the event was successfully sent.
1203+ # Complete the corresponding send_event task.
1204+ event_id = event .eventId
1205+ send_event_task = ctx ._pending_tasks .pop (event_id , None )
1206+ if send_event_task :
1207+ # For send_event, we don't return any meaningful result, just completion
1208+ send_event_task .complete (None )
1209+ ctx .resume ()
1210+ # Also remove the corresponding action from pending actions
1211+ ctx ._pending_actions .pop (event_id , None )
11911212 elif event .HasField ("executionSuspended" ):
11921213 if not self ._is_suspended and not ctx .is_replaying :
11931214 self ._logger .info (f"{ ctx .instance_id } : Execution suspended." )
@@ -1304,8 +1325,8 @@ def _get_method_name_for_action(action: pb.OrchestratorAction) -> str:
13041325 return task .get_name (task .OrchestrationContext .create_timer )
13051326 elif action_type == "createSubOrchestration" :
13061327 return task .get_name (task .OrchestrationContext .call_sub_orchestrator )
1307- # elif action_type == "sendEvent":
1308- # return task.get_name(task.OrchestrationContext.send_event)
1328+ elif action_type == "sendEvent" :
1329+ return task .get_name (task .OrchestrationContext .send_event )
13091330 else :
13101331 raise NotImplementedError (f"Action type '{ action_type } ' not supported!" )
13111332
0 commit comments