Skip to main content

Instances

Struct Instances 

Source
pub struct Instances<E> { /* private fields */ }
Expand description

Runs the store’s instances on an engine. Each instance runs one revision in its own compose project, on its own slot and under its own host label, so two revisions of one environment run side by side:

  • project <workspace>_<env>_r<revision>: trestle names can’t contain _, so a project name parses back to its parts and reconcile tells instance projects from any other;
  • host label <workspace>-<env>-r<revision> (demo-dev-r2.localhost);
  • the slot the store leases the instance, host-wide.

The rendered tree lives in <state>/instances/<id>/ (owner-only) and is a cache, re-rendered from the revision on every start. It holds no credential: they reach Compose as process environment only (see MaterializedOutput::into_launch_env).

Implementations§

Source§

impl<E: ComposeEngine> Instances<E>

Source

pub fn new(store: Arc<Store>, engine: E, state_dir: impl Into<PathBuf>) -> Self

Run store’s instances on engine, materializing them under state_dir (<state_dir>/instances/<id>/). Secrets resolve with the env provider only until with_providers says otherwise.

Source

pub fn with_providers(self, providers: SecretProviders) -> Self

Resolve secrets with providers (and no others).

Source

pub fn with_source(self, source: impl Source + 'static) -> Self

Make source available to instances that name it.

Source

pub fn without_port_probe(self) -> Self

Don’t check host ports before starting (tests on a shared host, a fake engine).

Source

pub fn with_wait_timeout(self, timeout: Duration) -> Self

Give up waiting for health after timeout on start.

Source

pub fn engine(&self) -> &E

The engine.

Source

pub fn store(&self) -> &Store

The store.

Source

pub fn dir(&self, id: &InstanceId) -> PathBuf

Where the instance’s tree is materialized.

Source

pub fn placement( &self, id: &InstanceId, ) -> Result<RuntimePlacement, InstanceError>

Where the instance runs: its compose project, host label, mesh and slot. Leases it a slot if it has none.

Source

pub async fn effective_env( &self, id: &InstanceId, ) -> Result<EffectiveEnv, InstanceError>

The instance’s environment, every variable with its provenance (see EffectiveEnv).

Source

pub async fn materialize( &self, id: &InstanceId, ) -> Result<Materialized, InstanceError>

Render the instance into its directory, from scratch, and return what it launches with. The tree holds no credential.

Source

pub async fn start( &self, id: &InstanceId, ) -> Result<Materialized, InstanceError>

Start the instance: lease it a slot (if it has none), check its host ports, render it afresh and up it, waiting for health. The store records it as wanted running first, so a crash mid-start is reconciled as running.

Source

pub async fn stop( &self, id: &InstanceId, volumes: bool, ) -> Result<(), InstanceError>

Stop the instance (down, with its volumes when volumes), keeping its slot.

When a source fails (a Neon outage, say), the tree rendered at the last start is taken down without its launch env: Compose then interpolates the missing variables as empty, which down doesn’t mind, so a source never keeps an instance from stopping.

Source

pub async fn remove( &self, id: &InstanceId, volumes: bool, ) -> Result<(), InstanceError>

Stop the instance if it runs, drop its tree, and delete it from the store (releasing its slot).

Source

pub async fn health( &self, id: &InstanceId, ) -> Result<BTreeMap<String, Health>, InstanceError>

The health of each of the instance’s services (empty when it doesn’t run).

Source

pub async fn events( &self, id: &InstanceId, ) -> Result<EngineStream<InstanceEvent>, InstanceError>

The instance’s events from now on: its containers’ lifecycle and health changes.

Source

pub async fn reconcile( &self, opts: ReconcileOptions, ) -> Result<Reconciled, InstanceError>

Match what Docker runs against the store, after a restart of the runtime: a running instance project is adopted (its instance marked running), an instance wanted running whose project is gone is marked stopped, and an instance-shaped project the store doesn’t know is an orphan (taken down with ReconcileOptions::remove_orphans).

Auto Trait Implementations§

§

impl<E> !RefUnwindSafe for Instances<E>

§

impl<E> !UnwindSafe for Instances<E>

§

impl<E> Freeze for Instances<E>
where E: Freeze,

§

impl<E> Send for Instances<E>
where E: Send,

§

impl<E> Sync for Instances<E>
where E: Sync,

§

impl<E> Unpin for Instances<E>
where E: Unpin,

§

impl<E> UnsafeUnpin for Instances<E>
where E: UnsafeUnpin,

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, 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 = !

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.