@@ -22,6 +22,7 @@ use tedge_api::mqtt_topics::EntityTopicError;
2222use tedge_api:: mqtt_topics:: EntityTopicId ;
2323use tedge_api:: mqtt_topics:: MqttSchema ;
2424use tedge_api:: mqtt_topics:: OperationType ;
25+ use tedge_api:: mqtt_topics:: SignalType ;
2526use tedge_api:: workflow:: extract_json_output;
2627use tedge_api:: workflow:: CommandBoard ;
2728use tedge_api:: workflow:: CommandId ;
@@ -139,11 +140,55 @@ impl WorkflowActor {
139140 /// but also from *this* actor as all its state transitions are published over MQTT.
140141 /// Only the former will be actually processed with [Self::process_command_update].
141142 async fn process_mqtt_message ( & mut self , message : MqttMessage ) -> Result < ( ) , RuntimeError > {
142- let Ok ( ( operation , cmd_id ) ) = self . extract_command_identifiers ( & message. topic . name ) else {
143- log:: error!( "Unknown command channel : {}" , & message. topic. name) ;
143+ let Ok ( ( _ , channel ) ) = self . mqtt_schema . entity_channel_of ( & message. topic ) else {
144+ log:: error!( "Unknown topic : {}" , & message. topic. name) ;
144145 return Ok ( ( ) ) ;
145146 } ;
147+ match channel {
148+ Channel :: Command { operation, cmd_id } => {
149+ self . process_command_message ( message, operation, cmd_id)
150+ . await
151+ }
152+ Channel :: Signal { signal_type } => {
153+ self . process_signal_message ( message, signal_type) . await
154+ }
155+ _ => {
156+ error ! ( "Unsupported channel: {}" , channel) ;
157+ Ok ( ( ) )
158+ }
159+ }
160+ }
146161
162+ async fn process_signal_message (
163+ & mut self ,
164+ _message : MqttMessage ,
165+ signal_type : SignalType ,
166+ ) -> Result < ( ) , RuntimeError > {
167+ match signal_type {
168+ SignalType :: Sync => {
169+ info ! ( "Received sync signal, requesting all builtin actors to sync" ) ;
170+ self . sync_signal_dispatcher . sync_all ( ) . await ?;
171+ }
172+ SignalType :: SyncOperation ( operation) => {
173+ info ! (
174+ "Received sync signal for {}, requesting the corresponding actor to sync" ,
175+ operation
176+ ) ;
177+ self . sync_signal_dispatcher . sync ( operation) . await ?;
178+ }
179+ SignalType :: Custom ( _) => {
180+ // Custom signal types are not handled yet
181+ }
182+ }
183+ Ok ( ( ) )
184+ }
185+
186+ async fn process_command_message (
187+ & mut self ,
188+ message : MqttMessage ,
189+ operation : OperationType ,
190+ cmd_id : String ,
191+ ) -> Result < ( ) , RuntimeError > {
147192 let Ok ( state) = GenericCommandState :: from_command_message ( & message) else {
148193 log:: error!( "Invalid command payload: {}" , & message. topic. name) ;
149194 return Ok ( ( ) ) ;
@@ -430,7 +475,7 @@ impl WorkflowActor {
430475 new_state : GenericCommandState ,
431476 ) -> Result < ( ) , RuntimeError > {
432477 if new_state. is_finished ( ) {
433- self . sync_dependent_actors ( & new_state) . await ?;
478+ self . sync_listener_actors ( & new_state) . await ?;
434479 self . finalize_builtin_command_update ( new_state) . await ?;
435480
436481 Ok ( ( ) )
@@ -463,13 +508,13 @@ impl WorkflowActor {
463508 self . process_command_update ( adapted_state) . await
464509 }
465510
466- async fn sync_dependent_actors (
511+ async fn sync_listener_actors (
467512 & mut self ,
468513 command : & GenericCommandState ,
469514 ) -> Result < ( ) , RuntimeError > {
470515 if let Some ( command) = command. operation ( ) {
471516 self . sync_signal_dispatcher
472- . send ( command. as_str ( ) . into ( ) )
517+ . sync_listener ( command. as_str ( ) . into ( ) )
473518 . await ?;
474519 }
475520 Ok ( ( ) )
0 commit comments