优化连接流程:connect_from_source自动处理订阅,简化main.rs
This commit is contained in:
parent
a2217a991c
commit
494cf1d656
|
|
@ -395,7 +395,13 @@ impl ConnectionManager {
|
||||||
source.username.as_deref(),
|
source.username.as_deref(),
|
||||||
source.password.as_deref(),
|
source.password.as_deref(),
|
||||||
)
|
)
|
||||||
.await
|
.await?;
|
||||||
|
|
||||||
|
// Subscribe to points for this source
|
||||||
|
self.subscribe_points_from_source(source_id, None, pool)
|
||||||
|
.await?;
|
||||||
|
|
||||||
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn connect(
|
pub async fn connect(
|
||||||
|
|
|
||||||
12
src/main.rs
12
src/main.rs
|
|
@ -62,16 +62,8 @@ async fn main() {
|
||||||
let source_id = source.id;
|
let source_id = source.id;
|
||||||
|
|
||||||
let task = tokio::spawn(async move {
|
let task = tokio::spawn(async move {
|
||||||
match cm.connect_from_source(&p, source_id).await {
|
if let Err(e) = cm.connect_from_source(&p, source_id).await {
|
||||||
Ok(_) => {
|
tracing::error!("Failed to connect to source {}: {}", source_name, e);
|
||||||
// Subscribe to points for this source
|
|
||||||
if let Err(e) = cm.subscribe_points_from_source(source_id, None, &p).await {
|
|
||||||
tracing::error!("Failed to subscribe to points for source {}: {}", source_name, e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Err(e) => {
|
|
||||||
tracing::error!("Failed to connect to source {}: {}", source_name, e);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue