Improve code format in router
Signed-off-by: Lee Smet <lee.smet@hotmail.com>
This commit is contained in:
170
src/router.rs
170
src/router.rs
@@ -227,62 +227,63 @@ async fn deliver_one(
|
|||||||
// Stop on terminal states
|
// Stop on terminal states
|
||||||
if matches!(s, TransportStatus::Delivered | TransportStatus::Read) {
|
if matches!(s, TransportStatus::Delivered | TransportStatus::Read) {
|
||||||
// On Read, fetch supervisor job.status and update local job/message if terminal
|
// On Read, fetch supervisor job.status and update local job/message if terminal
|
||||||
if matches!(s, TransportStatus::Read) {
|
if matches!(s, TransportStatus::Read)
|
||||||
if let Some(job_id) = job_id_opt {
|
&& let Some(job_id) = job_id_opt
|
||||||
let sup = SupervisorClient::new_with_client(
|
{
|
||||||
client.clone(),
|
let sup = SupervisorClient::new_with_client(
|
||||||
sup_dest.clone(),
|
client.clone(),
|
||||||
sup_topic.clone(),
|
sup_dest.clone(),
|
||||||
None,
|
sup_topic.clone(),
|
||||||
);
|
None,
|
||||||
match sup.job_status_sync(job_id.to_string(), 10).await {
|
);
|
||||||
Ok(remote_status) => {
|
match sup.job_status_sync(job_id.to_string(), 10).await {
|
||||||
if let Some((mapped, terminal)) =
|
Ok(remote_status) => {
|
||||||
map_supervisor_job_status(&remote_status)
|
if let Some((mapped, terminal)) =
|
||||||
{
|
map_supervisor_job_status(&remote_status)
|
||||||
if terminal {
|
{
|
||||||
let _ = service_poll
|
if terminal {
|
||||||
.update_job_status_unchecked(
|
let _ = service_poll
|
||||||
context_id,
|
.update_job_status_unchecked(
|
||||||
caller_id,
|
context_id,
|
||||||
job_id,
|
caller_id,
|
||||||
mapped.clone(),
|
job_id,
|
||||||
)
|
mapped.clone(),
|
||||||
.await;
|
)
|
||||||
|
.await;
|
||||||
|
|
||||||
// After terminal status, fetch supervisor job.result and store into Job.result
|
// After terminal status, fetch supervisor job.result and store into Job.result
|
||||||
let sup = SupervisorClient::new_with_client(
|
let sup = SupervisorClient::new_with_client(
|
||||||
client.clone(),
|
client.clone(),
|
||||||
sup_dest.clone(),
|
sup_dest.clone(),
|
||||||
sup_topic.clone(),
|
sup_topic.clone(),
|
||||||
None,
|
None,
|
||||||
);
|
);
|
||||||
match sup
|
match sup
|
||||||
.job_result_sync(
|
.job_result_sync(
|
||||||
job_id.to_string(),
|
job_id.to_string(),
|
||||||
job_result_reply_timeout,
|
job_result_reply_timeout,
|
||||||
)
|
)
|
||||||
.await
|
.await
|
||||||
{
|
{
|
||||||
Ok(result_map) => {
|
Ok(result_map) => {
|
||||||
// Persist the result into the Job.result map (merge)
|
// Persist the result into the Job.result map (merge)
|
||||||
let _ = service_poll
|
let _ = service_poll
|
||||||
.update_job_result_merge_unchecked(
|
.update_job_result_merge_unchecked(
|
||||||
context_id,
|
context_id,
|
||||||
caller_id,
|
caller_id,
|
||||||
job_id,
|
job_id,
|
||||||
result_map.clone(),
|
result_map.clone(),
|
||||||
)
|
)
|
||||||
.await;
|
.await;
|
||||||
// Log which key was stored (success or error)
|
// Log which key was stored (success or error)
|
||||||
let key = result_map
|
let key = result_map
|
||||||
.keys()
|
.keys()
|
||||||
.next()
|
.next()
|
||||||
.cloned()
|
.cloned()
|
||||||
.unwrap_or_else(|| {
|
.unwrap_or_else(|| {
|
||||||
"unknown".to_string()
|
"unknown".to_string()
|
||||||
});
|
});
|
||||||
let _ = service_poll
|
let _ = service_poll
|
||||||
.append_message_logs(
|
.append_message_logs(
|
||||||
context_id,
|
context_id,
|
||||||
caller_id,
|
caller_id,
|
||||||
@@ -293,9 +294,9 @@ async fn deliver_one(
|
|||||||
)],
|
)],
|
||||||
)
|
)
|
||||||
.await;
|
.await;
|
||||||
}
|
}
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
let _ = service_poll
|
let _ = service_poll
|
||||||
.append_message_logs(
|
.append_message_logs(
|
||||||
context_id,
|
context_id,
|
||||||
caller_id,
|
caller_id,
|
||||||
@@ -306,19 +307,19 @@ async fn deliver_one(
|
|||||||
)],
|
)],
|
||||||
)
|
)
|
||||||
.await;
|
.await;
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Mark message as processed
|
// Mark message as processed
|
||||||
let _ = service_poll
|
let _ = service_poll
|
||||||
.update_message_status(
|
.update_message_status(
|
||||||
context_id,
|
context_id,
|
||||||
caller_id,
|
caller_id,
|
||||||
id,
|
id,
|
||||||
MessageStatus::Processed,
|
MessageStatus::Processed,
|
||||||
)
|
)
|
||||||
.await;
|
.await;
|
||||||
let _ = service_poll
|
let _ = service_poll
|
||||||
.append_message_logs(
|
.append_message_logs(
|
||||||
context_id,
|
context_id,
|
||||||
caller_id,
|
caller_id,
|
||||||
@@ -329,32 +330,31 @@ async fn deliver_one(
|
|||||||
)],
|
)],
|
||||||
)
|
)
|
||||||
.await;
|
.await;
|
||||||
}
|
|
||||||
} else {
|
|
||||||
let _ = service_poll
|
|
||||||
.append_message_logs(
|
|
||||||
context_id,
|
|
||||||
caller_id,
|
|
||||||
id,
|
|
||||||
vec![format!(
|
|
||||||
"Unknown supervisor status '{}' for job {}",
|
|
||||||
remote_status, job_id
|
|
||||||
)],
|
|
||||||
)
|
|
||||||
.await;
|
|
||||||
}
|
}
|
||||||
}
|
} else {
|
||||||
Err(e) => {
|
|
||||||
let _ = service_poll
|
let _ = service_poll
|
||||||
.append_message_logs(
|
.append_message_logs(
|
||||||
context_id,
|
context_id,
|
||||||
caller_id,
|
caller_id,
|
||||||
id,
|
id,
|
||||||
vec![format!("job.status sync error: {}", e)],
|
vec![format!(
|
||||||
|
"Unknown supervisor status '{}' for job {}",
|
||||||
|
remote_status, job_id
|
||||||
|
)],
|
||||||
)
|
)
|
||||||
.await;
|
.await;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Err(e) => {
|
||||||
|
let _ = service_poll
|
||||||
|
.append_message_logs(
|
||||||
|
context_id,
|
||||||
|
caller_id,
|
||||||
|
id,
|
||||||
|
vec![format!("job.status sync error: {}", e)],
|
||||||
|
)
|
||||||
|
.await;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
Reference in New Issue
Block a user