pub struct GenericStartup {
pub options: StartupOptions,
pub mount_paths: Vec<String>,
pub registrant: Option<Arc<ConfigurationRegistrant>>,
pub job_registry: JobRegistry,
pub gateway: Option<Arc<GatewayConnect>>,
pub redis: Option<RedisStorage>,
pub server_addr: Option<SocketAddr>,
pub socket_addr: Option<SocketAddr>,
pub consumer_names: Vec<String>,
/* private fields */
}Expand description
Assembled service state produced by GenericStartup::bootstrap or manual init.
Holds the startup options, mounted route registrant, background job registry,
gateway connection, cache handle, bound addresses, recorded consumer names,
and whether OpenAPI specs were built. Pass &GenericStartup to registrars so
they can build controllers and consumers from this state.
Fields§
§options: StartupOptionsThe options this instance was created with.
mount_paths: Vec<String>URL path prefixes the service handles; also used for docs base and gateway registration.
registrant: Option<Arc<ConfigurationRegistrant>>HTTP router holder, set by GenericStartup::init. Required before mounting or serving.
job_registry: JobRegistryBackground job registry. Add jobs with GenericStartup::add_job, run with GenericStartup::run_jobs.
gateway: Option<Arc<GatewayConnect>>Gateway connection, set during GenericStartup::bootstrap when registration succeeds.
redis: Option<RedisStorage>Redis cache handle, set during GenericStartup::init when Redis is reachable.
server_addr: Option<SocketAddr>HTTP listen address derived from the configured server port.
socket_addr: Option<SocketAddr>Socket listen address derived from the configured socket port.
consumer_names: Vec<String>Queue names recorded from ConsumerRegistrar during bootstrap.
Implementations§
Source§impl GenericStartup
impl GenericStartup
Sourcepub fn new(options: StartupOptions) -> Self
pub fn new(options: StartupOptions) -> Self
Creates an empty startup with the given options and no mounted state.
Sourcepub fn with_mount_paths(self, paths: Vec<String>) -> Self
pub fn with_mount_paths(self, paths: Vec<String>) -> Self
Sets the URL path prefixes this service handles.
Sourcepub async fn init(&mut self) -> Result<()>
pub async fn init(&mut self) -> Result<()>
Performs global init: loads the environment, sets up tracing, resolves the
server and socket addresses, creates the route registrant, binds the docs
base to mount_paths, and connects to Redis on a best-effort basis.
Returns an error if the environment is invalid or an address fails to parse.
Redis failure only logs a warning and leaves GenericStartup::redis as None.
Sourcepub async fn bootstrap(
options: StartupOptions,
mount_paths: Vec<String>,
static_registrar: Option<Arc<dyn StaticRegistrar>>,
controller_registrar: Option<Arc<dyn ControllerRegistrar>>,
consumer_registrar: Option<Arc<dyn ConsumerRegistrar>>,
) -> Result<Self>
pub async fn bootstrap( options: StartupOptions, mount_paths: Vec<String>, static_registrar: Option<Arc<dyn StaticRegistrar>>, controller_registrar: Option<Arc<dyn ControllerRegistrar>>, consumer_registrar: Option<Arc<dyn ConsumerRegistrar>>, ) -> Result<Self>
Runs full startup: global init, static registration, gateway registration, controller mounting with OpenAPI spec building, and consumer recording.
options selects which subsystems run; mount_paths sets the handled URL
prefixes. Each registrar is optional: pass None for anything the caller
wires manually via the exposed GenericStartup fields. An empty
mount_paths skips gateway registration; gateway failure is logged and
does not fail bootstrap.
let startup = GenericStartup::bootstrap(opts, mount_paths, None, Some(controllers), None).await?;Sourcepub async fn mount_controller<C: RouteController + 'static>(
&self,
c: C,
) -> Result<()>
pub async fn mount_controller<C: RouteController + 'static>( &self, c: C, ) -> Result<()>
Mounts a controller’s routes onto the router. Errors if GenericStartup::init or GenericStartup::bootstrap has not run.
Sourcepub async fn mount_controller_boxed(
&self,
c: Box<dyn RouteController>,
) -> Result<()>
pub async fn mount_controller_boxed( &self, c: Box<dyn RouteController>, ) -> Result<()>
Mounts a boxed trait-object controller. Used for controllers built by ControllerRegistrar. Errors if not initialised.
Sourcepub async fn serve(&self) -> Result<SocketAddr>
pub async fn serve(&self) -> Result<SocketAddr>
Starts the HTTP server in the background and returns the bound address. Errors if not initialised.
Sourcepub async fn shutdown(&mut self) -> Result<()>
pub async fn shutdown(&mut self) -> Result<()>
Stops background jobs and deregisters from the gateway. Failures are logged as warnings; shutdown itself succeeds.
Sourcepub fn job_registry(&mut self) -> &mut JobRegistry
pub fn job_registry(&mut self) -> &mut JobRegistry
Returns the mutable job registry for manual wiring.
Sourcepub fn add_job<J: ServiceJob + 'static>(&mut self, job: J)
pub fn add_job<J: ServiceJob + 'static>(&mut self, job: J)
Adds a job to the registry. Jobs start only when GenericStartup::run_jobs is called.
Sourcepub async fn run_jobs(&mut self) -> Result<()>
pub async fn run_jobs(&mut self) -> Result<()>
Starts all registered jobs. No-ops with a log when enable_jobs is false or no jobs are registered.
Sourcepub async fn start_jobs(&mut self) -> Result<()>
pub async fn start_jobs(&mut self) -> Result<()>
Alias for GenericStartup::run_jobs.
Sourcepub fn registrant(&self) -> Option<Arc<ConfigurationRegistrant>>
pub fn registrant(&self) -> Option<Arc<ConfigurationRegistrant>>
Returns the route registrant, if initialised.
Sourcepub fn gateway_client(&self) -> Option<Arc<GatewayConnect>>
pub fn gateway_client(&self) -> Option<Arc<GatewayConnect>>
Returns the gateway connection, if registration succeeded.
Sourcepub fn redis_client(&self) -> Option<RedisStorage>
pub fn redis_client(&self) -> Option<RedisStorage>
Returns the Redis cache handle, if Redis was reachable at init.
Sourcepub fn server_addr(&self) -> Option<SocketAddr>
pub fn server_addr(&self) -> Option<SocketAddr>
Returns the resolved HTTP listen address, if initialised.
Sourcepub fn socket_addr(&self) -> Option<SocketAddr>
pub fn socket_addr(&self) -> Option<SocketAddr>
Returns the resolved socket listen address, if initialised.
Sourcepub fn router_handle(&self) -> Option<Arc<RwLock<Router>>>
pub fn router_handle(&self) -> Option<Arc<RwLock<Router>>>
Returns the shared router handle, if initialised.
Sourcepub fn is_production(&self) -> bool
pub fn is_production(&self) -> bool
Reports whether the loaded environment is production. Returns false when the environment is not provisioned.
Sourcepub fn docs_built(&self) -> bool
pub fn docs_built(&self) -> bool
Reports whether OpenAPI specs were built during bootstrap.
Sourcepub fn server_urls(&self) -> Vec<String>
pub fn server_urls(&self) -> Vec<String>
Returns the localhost server URLs for the configured server port (defaults to 8080 when unprovisioned).
Auto Trait Implementations§
impl !RefUnwindSafe for GenericStartup
impl !UnwindSafe for GenericStartup
impl Freeze for GenericStartup
impl Send for GenericStartup
impl Sync for GenericStartup
impl Unpin for GenericStartup
impl UnsafeUnpin for GenericStartup
Blanket Implementations§
Source§impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
Source§impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more