(
address: RpcAddress,
dependencies: Dependencies<S, ()>,
lifecycle: &ServerLifecycle,
)
| 254 | } |
| 255 | |
| 256 | fn start_rpc_server<S>( |
| 257 | address: RpcAddress, |
| 258 | dependencies: Dependencies<S, ()>, |
| 259 | lifecycle: &ServerLifecycle, |
| 260 | ) -> Result<(), Report<GraphError>> |
| 261 | where |
| 262 | S: StorePool + Send + Sync + 'static, |
| 263 | for<'p> S::Store<'p>: PrincipalStore, |
| 264 | { |
| 265 | let server = Server::new(harpc_server::ServerConfig::default()).change_context(GraphError)?; |
| 266 | let cancellation_token = server.cancellation_token(); |
| 267 | |
| 268 | let (router, task) = hash_graph_api::rpc::rpc_router( |
| 269 | Dependencies { |
| 270 | store: dependencies.store, |
| 271 | temporal_client: dependencies.temporal_client, |
| 272 | codec: JsonCodec, |
| 273 | }, |
| 274 | server.events(), |
| 275 | ); |
| 276 | |
| 277 | lifecycle.spawn("RPC task", async move { |
| 278 | task.await; |
| 279 | Ok(()) |
| 280 | }); |
| 281 | |
| 282 | // Bridge: when our shutdown token fires, cancel the harpc server's internal token |
| 283 | let shutdown = lifecycle.shutdown.clone(); |
| 284 | lifecycle.spawn("RPC shutdown bridge", async move { |
| 285 | shutdown.cancelled().await; |
| 286 | cancellation_token.cancel(); |
| 287 | Ok(()) |
| 288 | }); |
| 289 | |
| 290 | let socket_address: SocketAddr = SocketAddr::try_from(address).change_context(GraphError)?; |
| 291 | let mut address = Multiaddr::empty(); |
| 292 | match socket_address { |
| 293 | SocketAddr::V4(v4) => { |
| 294 | address.push(Protocol::Ip4(*v4.ip())); |
| 295 | address.push(Protocol::Tcp(v4.port())); |
| 296 | } |
| 297 | SocketAddr::V6(v6) => { |
| 298 | address.push(Protocol::Ip6(*v6.ip())); |
| 299 | address.push(Protocol::Tcp(v6.port())); |
| 300 | } |
| 301 | } |
| 302 | |
| 303 | #[expect(clippy::significant_drop_tightening, reason = "false positive")] |
| 304 | lifecycle.spawn("RPC server", async move { |
| 305 | let stream = server.listen(address).await.change_context(GraphError)?; |
| 306 | |
| 307 | harpc_server::serve::serve(stream, router).await; |
| 308 | Ok(()) |
| 309 | }); |
| 310 | |
| 311 | Ok(()) |
| 312 | } |
| 313 |
no test coverage detected