mirror of
https://github.com/neondatabase/neon.git
synced 2026-05-16 04:30:38 +00:00
## Problem It took me a while to understand the purpose of all the tasks spawned in the main functions. ## Summary of changes Utilising the type system and less macros, plus much more comments, document the shutdown procedure of each task in detail
28 lines
905 B
Rust
28 lines
905 B
Rust
use anyhow::{anyhow, bail};
|
|
use hyper::{Body, Request, Response, StatusCode};
|
|
use std::{convert::Infallible, net::TcpListener};
|
|
use tracing::info;
|
|
use utils::http::{endpoint, error::ApiError, json::json_response, RouterBuilder, RouterService};
|
|
|
|
async fn status_handler(_: Request<Body>) -> Result<Response<Body>, ApiError> {
|
|
json_response(StatusCode::OK, "")
|
|
}
|
|
|
|
fn make_router() -> RouterBuilder<hyper::Body, ApiError> {
|
|
endpoint::make_router().get("/v1/status", status_handler)
|
|
}
|
|
|
|
pub async fn task_main(http_listener: TcpListener) -> anyhow::Result<Infallible> {
|
|
scopeguard::defer! {
|
|
info!("http has shut down");
|
|
}
|
|
|
|
let service = || RouterService::new(make_router().build()?);
|
|
|
|
hyper::Server::from_tcp(http_listener)?
|
|
.serve(service().map_err(|e| anyhow!(e))?)
|
|
.await?;
|
|
|
|
bail!("hyper server without shutdown handling cannot shutdown successfully");
|
|
}
|