ServiceExecutor

Struct ServiceExecutor 

Source
pub struct ServiceExecutor<S> { /* private fields */ }
Expand description

Manages multiple service deployments across different sites within a worker thread.

§Context from service_async

The service_async crate introduces a refined Service trait that leverages impl Trait for improved performance and flexibility. It also provides the AsyncMakeService trait, which allows for efficient creation and updating of services, particularly useful for managing stateful resources across service updates.

§State Transfer Usefulness

State transfer can be particularly useful in scenarios such as:

  1. Database Connection Pools: When updating a service that manages database connections, transferring the existing pool can maintain active connections, avoiding the overhead of establishing new ones.

  2. In-Memory Caches: For services with large caches, transferring the cache state can prevent performance dips that would occur if the cache had to be rebuilt from scratch.

§Service Deployment Models

This system supports two deployment models:

§1. Two-Stage Deployment

This model is ideal for updating services while preserving state:

a) Staging: Prepare a new service instance, potentially using state from an existing service.

b) Deployment: Either update an existing service or deploy a new one.

This process allows for careful preparation and validation of the new service before it replaces the existing one, minimizing downtime and preserving valuable state.

§2. Single-Stage Deployment

This model is suitable for initial deployments or when state preservation isn’t necessary:

  • Create and deploy a service in one step using ServiceCommand::PrepareAndCommit
  • This is more straightforward but doesn’t allow for state transfer from existing services.

§Worker Thread Execution

The ServiceExecutor::run method serves as the main execution loop, processing ServiceCommandTasks containing ServiceCommands. It handles service creation, updates, and removal, coordinating with ServiceDeploymentContainer instances for each site.

Implementations§

Source§

impl<S> ServiceExecutor<S>

Source

pub async fn run<F, LF, A>(&self, rx: Receiver<ServiceCommandTask<F, LF>>)
where ServiceCommand<F, LF>: Execute<A, S>,

Runs the main control loop for the worker thread.

This method continuously processes incoming ServiceCommands and executes the corresponding actions on the managed services.

§Type Parameters
  • F: The service factory type
  • LF: The listener factory type
  • A: The type of the argument passed to the service
§Arguments

This method will run until the receiver channel is closed.

Trait Implementations§

Source§

impl<S> Default for ServiceExecutor<S>

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

§

impl<S> Freeze for ServiceExecutor<S>

§

impl<S> !RefUnwindSafe for ServiceExecutor<S>

§

impl<S> !Send for ServiceExecutor<S>

§

impl<S> !Sync for ServiceExecutor<S>

§

impl<S> Unpin for ServiceExecutor<S>

§

impl<S> !UnwindSafe for ServiceExecutor<S>

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<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> 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> 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 = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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