Skip to main content

bootstrap_with_release

Function bootstrap_with_release 

Source
pub fn bootstrap_with_release<F, Fut, T, E>(
    release: &str,
    body: F,
) -> Result<T, E>
where F: FnOnce(Shutdown) -> Fut, Fut: Future<Output = Result<T, E>>, E: From<WebServerError>,
Expand description

Runs body with observability, a runtime, and signal handling set up.

The ordering is the point: observability on the main thread first (so the Sentry hub reaches the runtime’s workers), then the runtime, then one signal listener whose Shutdown handle is passed to body, then the guard drops after body returns — flushing errors raised during the shutdown itself.

The application still owns main, so it can start as many servers as it likes.

It also owns the build-tool subcommands, so no project has to declare a second binary or write a line of glue to reach them:

$ my-server gen-static-assets    # icons, then hash everything but scripts
$ my-server gen-static-scripts   # hash the built JavaScript
$ my-server                      # serve

Those two exit before any runtime or error monitoring starts. They still read WSB_ENVIRONMENT, because main resolves it before calling in — set it to local in the build stage.

use webserver_base::{WebServer, WebServerError, bootstrap};

fn main() -> Result<(), WebServerError> {
    bootstrap!(|shutdown| async move { WebServer::from_env()?.run(shutdown).await })
}

§Errors

Whatever body returns. bootstrap adds no failure of its own.

§Panics

If the Tokio runtime cannot be built. There is no useful way to continue, and no server to report it to yet.