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:
-
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.
-
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.
- Use
ServiceCommand::Precommit - This leverages the
make_via_refmethod fromAsyncMakeService, allowing state transfer.
b) Deployment: Either update an existing service or deploy a new one.
- For updates:
ServiceCommand::Update - For new deployments:
ServiceCommand::Commit
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>
impl<S> ServiceExecutor<S>
Sourcepub async fn run<F, LF, A>(&self, rx: Receiver<ServiceCommandTask<F, LF>>)where
ServiceCommand<F, LF>: Execute<A, S>,
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 typeLF: The listener factory typeA: The type of the argument passed to the service
§Arguments
rx: A receiver channel forUpdates containingServiceCommands
This method will run until the receiver channel is closed.