@@ -17,9 +17,9 @@ use std::{
1717use temporal_sdk_core_protos:: {
1818 coresdk:: {
1919 workflow_activation:: {
20- FireTimer , NotifyHasPatch , ResolveActivity , ResolveChildWorkflowExecution ,
21- ResolveChildWorkflowExecutionStart , WorkflowActivation , WorkflowActivationJob ,
22- workflow_activation_job:: Variant ,
20+ FireTimer , InitializeWorkflow , NotifyHasPatch , ResolveActivity ,
21+ ResolveChildWorkflowExecution , ResolveChildWorkflowExecutionStart , WorkflowActivation ,
22+ WorkflowActivationJob , workflow_activation_job:: Variant ,
2323 } ,
2424 workflow_commands:: {
2525 CancelChildWorkflowExecution , CancelSignalWorkflow , CancelTimer ,
@@ -44,26 +44,25 @@ use tracing::Instrument;
4444impl WorkflowFunction {
4545 /// Start a workflow function, returning a future that will resolve when the workflow does,
4646 /// and a channel that can be used to send it activations.
47- #[ doc( hidden) ]
48- pub fn start_workflow (
47+ pub ( crate ) fn start_workflow (
4948 & self ,
5049 namespace : String ,
5150 task_queue : String ,
52- workflow_type : & str ,
53- args : Vec < Payload > ,
51+ init_workflow_job : InitializeWorkflow ,
5452 outgoing_completions : UnboundedSender < WorkflowActivationCompletion > ,
5553 ) -> (
5654 impl Future < Output = WorkflowResult < Payload > > + use < > ,
5755 UnboundedSender < WorkflowActivation > ,
5856 ) {
5957 let ( cancel_tx, cancel_rx) = watch:: channel ( None ) ;
60- let ( wf_context, cmd_receiver) = WfContext :: new ( namespace, task_queue, args, cancel_rx) ;
61- let ( tx, incoming_activations) = unbounded_channel ( ) ;
6258 let span = info_span ! (
6359 "RunWorkflow" ,
64- "otel.name" = format!( "RunWorkflow:{}" , workflow_type) ,
60+ "otel.name" = format!( "RunWorkflow:{}" , & init_workflow_job . workflow_type) ,
6561 "otel.kind" = "server"
6662 ) ;
63+ let ( wf_context, cmd_receiver) =
64+ WfContext :: new ( namespace, task_queue, init_workflow_job, cancel_rx) ;
65+ let ( tx, incoming_activations) = unbounded_channel ( ) ;
6766 let inner_fut = ( self . wf_func ) ( wf_context. clone ( ) ) . instrument ( span) ;
6867 (
6968 WorkflowFuture {
@@ -346,7 +345,7 @@ impl Future for WorkflowFuture {
346345 fn poll ( mut self : Pin < & mut Self > , cx : & mut Context < ' _ > ) -> Poll < Self :: Output > {
347346 ' activations: loop {
348347 // WF must always receive an activation first before responding with commands
349- let mut activation = match self . incoming_activations . poll_recv ( cx) {
348+ let activation = match self . incoming_activations . poll_recv ( cx) {
350349 Poll :: Ready ( a) => match a {
351350 Some ( act) => act,
352351 None => {
@@ -374,18 +373,6 @@ impl Future for WorkflowFuture {
374373
375374 let mut die_of_eviction_when_done = false ;
376375 let mut activation_cmds = vec ! [ ] ;
377- // Assign initial state from start workflow job
378- if let Some ( start_info) = activation. jobs . iter_mut ( ) . find_map ( |j| {
379- if let Some ( Variant :: InitializeWorkflow ( s) ) = j. variant . as_mut ( ) {
380- Some ( s)
381- } else {
382- None
383- }
384- } ) {
385- let mut wlock = self . wf_ctx . shared . write ( ) ;
386- wlock. random_seed = start_info. randomness_seed ;
387- wlock. search_attributes = start_info. search_attributes . take ( ) . unwrap_or_default ( ) ;
388- } ;
389376 // Lame hack to avoid hitting "unregistered" update handlers in a situation where
390377 // the history has no commands until an update is accepted. Will go away w/ SDK redesign
391378 if activation
0 commit comments