Skip to content

Commit

Permalink
Merge pull request #1 from rpcpool/add_health_endpoint
Browse files Browse the repository at this point in the history
add a health endpoint
  • Loading branch information
linuskendall authored Oct 24, 2024
2 parents c8a8c04 + 7a0ebf5 commit dd7b81f
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
7 changes: 7 additions & 0 deletions src/api/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,13 @@ impl PhotonApi {
.map_err(Into::into)
}

pub async fn health(&self) -> Result<(), PhotonApiError> {
self.get_indexer_health()
.await
.map(|_| ())
.map_err(Into::into)
}

pub async fn get_compressed_account(
&self,
request: CompressedAccountRequest,
Expand Down
10 changes: 9 additions & 1 deletion src/api/rpc_server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ pub async fn run_server(api: PhotonApi, port: u16) -> Result<ServerHandle, anyho
let middleware = tower::ServiceBuilder::new()
.layer(cors)
.layer(ProxyGetRequestLayer::new("/liveness", "liveness")?)
.layer(ProxyGetRequestLayer::new("/readiness", "readiness")?);
.layer(ProxyGetRequestLayer::new("/readiness", "readiness")?)
.layer(ProxyGetRequestLayer::new("/health", "health")?);
let server = ServerBuilder::default()
.set_middleware(middleware)
.build(addr)
Expand All @@ -43,6 +44,13 @@ fn build_rpc_module(api_and_indexer: PhotonApi) -> Result<RpcModule<PhotonApi>,
api.readiness().await.map_err(Into::into)
})?;

module.register_async_method("health", |_rpc_params, rpc_context| async move {
debug!("Checking Health");
let api = rpc_context.as_ref();
api.health().await.map_err(Into::into)
})?;


module.register_async_method(
"getCompressedAccount",
|rpc_params, rpc_context| async move {
Expand Down

0 comments on commit dd7b81f

Please sign in to comment.