Skip to content

Commit

Permalink
Merge pull request #3049 from rina23q/improve/accept-extra-mqtt-messa…
Browse files Browse the repository at this point in the history
…ges-in-the-executing-state

refactor: CommandStatus::Executing takes extra MQTT messages
  • Loading branch information
rina23q authored Aug 2, 2024
2 parents bbfef48 + 094ec0b commit ee032a8
Show file tree
Hide file tree
Showing 7 changed files with 28 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,9 @@ impl OperationContext {
let cmd_id = command.cmd_id.as_str();

match command.status() {
CommandStatus::Executing => Ok(OperationOutcome::Executing),
CommandStatus::Executing => Ok(OperationOutcome::Executing {
extra_messages: vec![],
}),
CommandStatus::Successful => {
// Send a request to the Downloader to download the file asynchronously from FTS
let config_filename = format!(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,9 @@ impl OperationContext {
let sm_topic = &target.smartrest_publish_topic;

match command.status() {
CommandStatus::Executing => Ok(OperationOutcome::Executing),
CommandStatus::Executing => Ok(OperationOutcome::Executing {
extra_messages: vec![],
}),
CommandStatus::Successful => {
let smartrest_operation_status = succeed_operation_no_payload(
CumulocitySupportedOperations::C8yDownloadConfigFile,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,9 @@ impl OperationContext {
let sm_topic = &target.smartrest_publish_topic;

match command.status() {
CommandStatus::Executing => Ok(OperationOutcome::Executing),
CommandStatus::Executing => Ok(OperationOutcome::Executing {
extra_messages: vec![],
}),
CommandStatus::Successful => {
let smartrest_operation_status =
succeed_operation_no_payload(CumulocitySupportedOperations::C8yFirmware);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,9 @@ impl OperationContext {
let smartrest_topic = &target.smartrest_publish_topic;

match command.status() {
CommandStatus::Executing => Ok(OperationOutcome::Executing),
CommandStatus::Executing => Ok(OperationOutcome::Executing {
extra_messages: vec![],
}),
CommandStatus::Successful => {
// Send a request to the Downloader to download the file asynchronously from FTS
let log_filename = format!("{}-{}", command.payload.log_type, cmd_id);
Expand Down
16 changes: 10 additions & 6 deletions crates/extensions/c8y_mapper_ext/src/operations/handlers/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -148,14 +148,17 @@ impl OperationContext {
&entity.smartrest_publish_topic,
) {
OperationOutcome::Ignored => UpdateStatus::Ongoing,
OperationOutcome::Executing => {
OperationOutcome::Executing { mut extra_messages } => {
let c8y_state_executing_payload = set_operation_executing(c8y_operation);
let c8y_state_executing_message =
MqttMessage::new(&entity.smartrest_publish_topic, c8y_state_executing_payload);
mqtt_publisher
.send(c8y_state_executing_message)
.await
.unwrap();

let mut messages = vec![c8y_state_executing_message];
messages.append(&mut extra_messages);

for message in messages {
mqtt_publisher.send(message).await.unwrap();
}

UpdateStatus::Ongoing
}
Expand Down Expand Up @@ -209,7 +212,8 @@ pub(super) enum OperationOutcome {
Ignored,

/// Update C8y operation state to `EXECUTING`.
Executing,
/// `extra_messages` can be used if an operation requires more than the status update message.
Executing { extra_messages: Vec<MqttMessage> },

/// Operation is terminated.
///
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,9 @@ impl OperationContext {
let topic = &target.smartrest_publish_topic;

match command.status() {
CommandStatus::Executing => Ok(OperationOutcome::Executing),
CommandStatus::Executing => Ok(OperationOutcome::Executing {
extra_messages: vec![],
}),
CommandStatus::Successful => {
let smartrest_set_operation =
smartrest::smartrest_serializer::succeed_operation_no_payload(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,9 @@ impl OperationContext {
// The command has not been processed yet
Ok(OperationOutcome::Ignored)
}
CommandStatus::Executing => Ok(OperationOutcome::Executing),
CommandStatus::Executing => Ok(OperationOutcome::Executing {
extra_messages: vec![],
}),
CommandStatus::Successful => {
let smartrest_set_operation =
smartrest::smartrest_serializer::succeed_operation_no_payload(
Expand Down

0 comments on commit ee032a8

Please sign in to comment.