@@ -133,10 +133,24 @@ def new_workflow_stub(self, cls: Type, workflow_options: WorkflowOptions = None)
133133 stub_cls = type (cls .__name__ , (WorkflowStub ,), attrs )
134134 return stub_cls ()
135135
136+ def new_workflow_stub_from_workflow_id (self , cls : Type , workflow_id : str ):
137+ """
138+ Use it to send signals or queries to a running workflow.
139+ Do not call workflow methods on it
140+ """
141+ stub_instance = self .new_workflow_stub (cls )
142+ execution = WorkflowExecution (workflow_id = workflow_id , run_id = None )
143+ stub_instance ._execution = execution
144+ return stub_instance
145+
136146 def wait_for_close (self , context : WorkflowExecutionContext ) -> object :
147+ return self .wait_for_close_with_workflow_id (workflow_id = context .workflow_execution .workflow_id ,
148+ run_id = context .workflow_execution .run_id ,
149+ workflow_type = context .workflow_type )
150+
151+ def wait_for_close_with_workflow_id (self , workflow_id : str , run_id : str = None , workflow_type : str = None ):
137152 while True :
138- history_request = create_close_history_event_request (self , context .workflow_execution .workflow_id ,
139- context .workflow_execution .run_id )
153+ history_request = create_close_history_event_request (self , workflow_id , run_id )
140154 history_response , err = self .service .get_workflow_execution_history (history_request )
141155 if err :
142156 raise Exception (err )
@@ -152,8 +166,9 @@ def wait_for_close(self, context: WorkflowExecutionContext) -> object:
152166 exception = deserialize_exception (attributes .details )
153167 if isinstance (exception , ActivityFailureException ):
154168 exception .set_cause ()
155- raise WorkflowFailureException (workflow_type = context .workflow_type ,
156- execution = context .workflow_execution ) from exception
169+ workflow_execution = WorkflowExecution (workflow_id = workflow_id , run_id = run_id )
170+ raise WorkflowFailureException (workflow_type = workflow_type ,
171+ execution = workflow_execution ) from exception
157172 else :
158173 details : Dict = json .loads (attributes .details )
159174 detail_message = details .get ("detailMessage" , "" )
0 commit comments