@@ -3,6 +3,7 @@ use crate::operation_workflows::actor::InternalCommandState;
33use crate :: operation_workflows:: actor:: WorkflowActor ;
44use crate :: operation_workflows:: config:: OperationConfig ;
55use crate :: operation_workflows:: message_box:: CommandDispatcher ;
6+ use crate :: operation_workflows:: message_box:: SyncSignalDispatcher ;
67use crate :: operation_workflows:: persist:: WorkflowRepository ;
78use crate :: state_repository:: state:: agent_state_dir;
89use crate :: state_repository:: state:: AgentStateRepository ;
@@ -22,13 +23,15 @@ use tedge_actors::RuntimeRequest;
2223use tedge_actors:: RuntimeRequestSink ;
2324use tedge_actors:: Service ;
2425use tedge_actors:: UnboundedLoggingReceiver ;
26+ use tedge_api:: commands:: CmdMetaSyncSignal ;
2527use tedge_api:: mqtt_topics:: ChannelFilter :: AnyCommand ;
2628use tedge_api:: mqtt_topics:: EntityFilter ;
2729use tedge_api:: mqtt_topics:: EntityTopicId ;
2830use tedge_api:: mqtt_topics:: MqttSchema ;
2931use tedge_api:: workflow:: GenericCommandData ;
3032use tedge_api:: workflow:: GenericCommandState ;
3133use tedge_api:: workflow:: OperationName ;
34+ use tedge_api:: workflow:: SyncOnCommand ;
3235use tedge_file_system_ext:: FsWatchEvent ;
3336use tedge_mqtt_ext:: MqttMessage ;
3437use tedge_mqtt_ext:: TopicFilter ;
@@ -39,6 +42,7 @@ pub struct WorkflowActorBuilder {
3942 input_sender : DynSender < AgentInput > ,
4043 input_receiver : UnboundedLoggingReceiver < AgentInput > ,
4144 command_dispatcher : CommandDispatcher ,
45+ sync_signal_dispatcher : SyncSignalDispatcher ,
4246 command_sender : DynSender < InternalCommandState > ,
4347 mqtt_publisher : LoggingSender < MqttMessage > ,
4448 script_runner : ClientMessageBox < Execute , std:: io:: Result < Output > > ,
@@ -65,6 +69,8 @@ impl WorkflowActorBuilder {
6569 let command_dispatcher = CommandDispatcher :: default ( ) ;
6670 let command_sender = input_sender. sender_clone ( ) ;
6771
72+ let sync_signal_dispatcher = SyncSignalDispatcher :: default ( ) ;
73+
6874 let mqtt_publisher = mqtt_actor. get_sender ( ) ;
6975 mqtt_actor. connect_sink (
7076 Self :: subscriptions ( & config. mqtt_schema , & config. device_topic_id ) ,
@@ -81,6 +87,7 @@ impl WorkflowActorBuilder {
8187 input_sender,
8288 input_receiver,
8389 command_dispatcher,
90+ sync_signal_dispatcher,
8491 command_sender,
8592 mqtt_publisher,
8693 signal_sender,
@@ -98,7 +105,19 @@ impl WorkflowActorBuilder {
98105 actor. connect_sink ( NoConfig , & self . input_sender ) ;
99106 for ( operation, sender) in actor. into_iter ( ) {
100107 self . command_dispatcher
101- . register_operation_handler ( operation, sender)
108+ . register_operation_handler ( operation, sender) ;
109+ }
110+ }
111+
112+ /// Register an actor to receive sync signals on completion of other commands
113+ pub fn register_sync_signal_sink < OperationActor > ( & mut self , actor : & OperationActor )
114+ where
115+ OperationActor : MessageSink < CmdMetaSyncSignal > + SyncOnCommand ,
116+ {
117+ let sender = actor. get_sender ( ) ;
118+ for operation in actor. sync_on_commands ( ) {
119+ self . sync_signal_dispatcher
120+ . register_sync_signal_sender ( operation, sender. sender_clone ( ) ) ;
102121 }
103122 }
104123
@@ -136,6 +155,7 @@ impl Builder<WorkflowActor> for WorkflowActorBuilder {
136155 log_dir : self . config . log_dir ,
137156 input_receiver : self . input_receiver ,
138157 builtin_command_dispatcher : self . command_dispatcher ,
158+ sync_signal_dispatcher : self . sync_signal_dispatcher ,
139159 mqtt_publisher : self . mqtt_publisher ,
140160 command_sender : self . command_sender ,
141161 script_runner : self . script_runner ,
0 commit comments