Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: CommandStatus::Executing takes extra MQTT messages #3049

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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