[router] move grpc client from router to worker and builder (#10958)

This commit is contained in:
Simo Lin
2025-09-26 06:13:47 -04:00
committed by GitHub
parent 5c0efa562b
commit 1b011e68dc
4 changed files with 118 additions and 139 deletions

View File

@@ -100,7 +100,7 @@ impl BasicWorkerBuilder {
atomic::{AtomicBool, AtomicUsize},
Arc,
};
use tokio::sync::Mutex;
use tokio::sync::{Mutex, RwLock};
let metadata = WorkerMetadata {
url: self.url.clone(),
@@ -111,6 +111,10 @@ impl BasicWorkerBuilder {
health_config: self.health_config,
};
let grpc_client = Arc::new(RwLock::new(
self.grpc_client.map(|client| Arc::new(Mutex::new(client))),
));
BasicWorker {
metadata,
load_counter: Arc::new(AtomicUsize::new(0)),
@@ -119,7 +123,7 @@ impl BasicWorkerBuilder {
consecutive_failures: Arc::new(AtomicUsize::new(0)),
consecutive_successes: Arc::new(AtomicUsize::new(0)),
circuit_breaker: CircuitBreaker::with_config(self.circuit_breaker_config),
grpc_client: self.grpc_client.map(|client| Arc::new(Mutex::new(client))),
grpc_client,
}
}
}