@@ -3,12 +3,12 @@ use std::{collections::HashSet, sync::Arc};
|
||||
use serde_json::{Value, json};
|
||||
use tokio::sync::Semaphore;
|
||||
|
||||
use tracing::{info, warn, error};
|
||||
use crate::{
|
||||
clients::{Destination, SupervisorClient, MyceliumClient},
|
||||
clients::{Destination, MyceliumClient, SupervisorClient},
|
||||
models::{Job, JobStatus, Message, MessageStatus, ScriptType, TransportStatus},
|
||||
service::AppService,
|
||||
};
|
||||
use tracing::{error, info, warn};
|
||||
|
||||
#[derive(Clone, Debug)]
|
||||
pub struct RouterConfig {
|
||||
@@ -71,7 +71,8 @@ pub fn start_router(service: AppService, cfg: RouterConfig) -> Vec<tokio::task::
|
||||
// Ensure permit is dropped at end of task
|
||||
let _permit = permit;
|
||||
if let Err(e) =
|
||||
deliver_one(&service_task, &cfg_task, ctx_id, &key, mycelium).await
|
||||
deliver_one(&service_task, &cfg_task, ctx_id, &key, mycelium)
|
||||
.await
|
||||
{
|
||||
error!(context_id=ctx_id, key=%key, error=%e, "Delivery error");
|
||||
}
|
||||
@@ -256,7 +257,13 @@ async fn deliver_one(
|
||||
sup_topic.clone(),
|
||||
None,
|
||||
);
|
||||
match sup.job_result_sync(job_id.to_string(), job_result_reply_timeout).await {
|
||||
match sup
|
||||
.job_result_sync(
|
||||
job_id.to_string(),
|
||||
job_result_reply_timeout,
|
||||
)
|
||||
.await
|
||||
{
|
||||
Ok(result_map) => {
|
||||
// Persist the result into the Job.result map (merge)
|
||||
let _ = service_poll
|
||||
@@ -268,7 +275,13 @@ async fn deliver_one(
|
||||
)
|
||||
.await;
|
||||
// Log which key was stored (success or error)
|
||||
let key = result_map.keys().next().cloned().unwrap_or_else(|| "unknown".to_string());
|
||||
let key = result_map
|
||||
.keys()
|
||||
.next()
|
||||
.cloned()
|
||||
.unwrap_or_else(|| {
|
||||
"unknown".to_string()
|
||||
});
|
||||
let _ = service_poll
|
||||
.append_message_logs(
|
||||
context_id,
|
||||
@@ -337,10 +350,7 @@ async fn deliver_one(
|
||||
context_id,
|
||||
caller_id,
|
||||
id,
|
||||
vec![format!(
|
||||
"job.status sync error: {}",
|
||||
e
|
||||
)],
|
||||
vec![format!("job.status sync error: {}", e)],
|
||||
)
|
||||
.await;
|
||||
}
|
||||
@@ -434,7 +444,6 @@ fn map_supervisor_job_status(s: &str) -> Option<(JobStatus, bool)> {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/// Auto-discover contexts periodically and ensure a router loop exists for each.
|
||||
/// Returns a JoinHandle of the discovery task (router loops are detached).
|
||||
pub fn start_router_auto(service: AppService, cfg: RouterConfig) -> tokio::task::JoinHandle<()> {
|
||||
@@ -452,7 +461,7 @@ pub fn start_router_auto(service: AppService, cfg: RouterConfig) -> tokio::task:
|
||||
};
|
||||
let _ = start_router(service.clone(), cfg_ctx);
|
||||
active.insert(ctx_id);
|
||||
info!(context_id=ctx_id, "Started loop for context");
|
||||
info!(context_id = ctx_id, "Started loop for context");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user