Skip to main content

GenericStartup

Struct GenericStartup 

Source
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: StartupOptions

The 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: JobRegistry

Background 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

Source

pub fn new(options: StartupOptions) -> Self

Creates an empty startup with the given options and no mounted state.

Source

pub fn with_mount_paths(self, paths: Vec<String>) -> Self

Sets the URL path prefixes this service handles.

Source

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.

Source

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?;
Source

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.

Source

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.

Source

pub async fn serve(&self) -> Result<SocketAddr>

Starts the HTTP server in the background and returns the bound address. Errors if not initialised.

Source

pub async fn shutdown(&mut self) -> Result<()>

Stops background jobs and deregisters from the gateway. Failures are logged as warnings; shutdown itself succeeds.

Source

pub fn job_registry(&mut self) -> &mut JobRegistry

Returns the mutable job registry for manual wiring.

Source

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.

Source

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.

Source

pub async fn start_jobs(&mut self) -> Result<()>

Source

pub async fn stop_jobs(&mut self) -> Result<()>

Stops all running jobs.

Source

pub fn registrant(&self) -> Option<Arc<ConfigurationRegistrant>>

Returns the route registrant, if initialised.

Source

pub fn gateway_client(&self) -> Option<Arc<GatewayConnect>>

Returns the gateway connection, if registration succeeded.

Source

pub fn redis_client(&self) -> Option<RedisStorage>

Returns the Redis cache handle, if Redis was reachable at init.

Source

pub fn server_addr(&self) -> Option<SocketAddr>

Returns the resolved HTTP listen address, if initialised.

Source

pub fn socket_addr(&self) -> Option<SocketAddr>

Returns the resolved socket listen address, if initialised.

Source

pub fn router_handle(&self) -> Option<Arc<RwLock<Router>>>

Returns the shared router handle, if initialised.

Source

pub fn is_production(&self) -> bool

Reports whether the loaded environment is production. Returns false when the environment is not provisioned.

Source

pub fn docs_built(&self) -> bool

Reports whether OpenAPI specs were built during bootstrap.

Source

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§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<'a, T, E> AsTaggedExplicit<'a, E> for T
where T: 'a,

Source§

fn explicit(self, class: Class, tag: u32) -> TaggedParser<'a, Explicit, Self, E>

Source§

impl<'a, T, E> AsTaggedImplicit<'a, E> for T
where T: 'a,

Source§

fn implicit( self, class: Class, constructed: bool, tag: u32, ) -> TaggedParser<'a, Implicit, Self, E>

Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CompatExt for T

Source§

fn compat(self) -> Compat<T>
where T: Sized,

Applies the Compat adapter by value. Read more
Source§

fn compat_ref(&self) -> Compat<&T>

Applies the Compat adapter by shared reference. Read more
Source§

fn compat_mut(&mut self) -> Compat<&mut T>

Applies the Compat adapter by mutable reference. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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
Source§

impl<T> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more