pub struct PgExperimentStore { /* private fields */ }Expand description
Postgres-backed ExperimentStore with a short-lived read-through cache.
Writes trigger pg_notify('autumn_experiments', name) so replicas can
invalidate their caches quickly via a background poll listener.
Implementations§
Source§impl PgExperimentStore
impl PgExperimentStore
Sourcepub const DEFAULT_CACHE_TTL: Duration
pub const DEFAULT_CACHE_TTL: Duration
Default read-through cache lifetime.
Sourcepub fn new(database_url: impl Into<String>) -> Self
pub fn new(database_url: impl Into<String>) -> Self
Create a store using the default 1 s read-through cache.
Sourcepub fn with_cache_ttl(
database_url: impl Into<String>,
cache_ttl: Duration,
) -> Self
pub fn with_cache_ttl( database_url: impl Into<String>, cache_ttl: Duration, ) -> Self
Create a store with an explicit cache TTL. Use Duration::ZERO to
disable caching.
Sourcepub fn from_database_config(config: &DatabaseConfig) -> Option<Self>
pub fn from_database_config(config: &DatabaseConfig) -> Option<Self>
Create a store from Autumn’s primary database configuration.
Sourcepub fn spawn_poll_listener(
store: Arc<Self>,
poll_interval: Duration,
) -> JoinHandle<()>
pub fn spawn_poll_listener( store: Arc<Self>, poll_interval: Duration, ) -> JoinHandle<()>
Spawn a background thread that polls autumn_experiment_changes and
invalidates this store’s cache for changed experiments.
The thread runs indefinitely; the returned handle can be detached.
Trait Implementations§
Source§impl Clone for PgExperimentStore
impl Clone for PgExperimentStore
Source§impl Debug for PgExperimentStore
impl Debug for PgExperimentStore
Source§impl ExperimentStore for PgExperimentStore
impl ExperimentStore for PgExperimentStore
Source§fn get(
&self,
name: &str,
) -> Result<Option<ExperimentConfig>, ExperimentStoreError>
fn get( &self, name: &str, ) -> Result<Option<ExperimentConfig>, ExperimentStoreError>
Source§fn list(&self) -> Result<Vec<ExperimentConfig>, ExperimentStoreError>
fn list(&self) -> Result<Vec<ExperimentConfig>, ExperimentStoreError>
Return all known experiments, sorted by name. Read more
Source§fn upsert(&self, config: ExperimentConfig) -> Result<(), ExperimentStoreError>
fn upsert(&self, config: ExperimentConfig) -> Result<(), ExperimentStoreError>
Insert or update an experiment configuration. Read more
Source§fn set_state(
&self,
name: &str,
state: ExperimentState,
winner: Option<&str>,
) -> Result<(), ExperimentStoreError>
fn set_state( &self, name: &str, state: ExperimentState, winner: Option<&str>, ) -> Result<(), ExperimentStoreError>
Update the lifecycle state of an experiment. Read more
Source§fn set_variants(
&self,
name: &str,
variants: Vec<VariantConfig>,
actor: Option<&str>,
) -> Result<(), ExperimentStoreError>
fn set_variants( &self, name: &str, variants: Vec<VariantConfig>, actor: Option<&str>, ) -> Result<(), ExperimentStoreError>
Update the variants and weights for an experiment. Read more
Source§fn get_assignment(
&self,
experiment: &str,
actor: &str,
) -> Result<Option<Assignment>, ExperimentStoreError>
fn get_assignment( &self, experiment: &str, actor: &str, ) -> Result<Option<Assignment>, ExperimentStoreError>
Source§fn record_assignment(
&self,
assignment: Assignment,
) -> Result<String, ExperimentStoreError>
fn record_assignment( &self, assignment: Assignment, ) -> Result<String, ExperimentStoreError>
Record a sticky assignment. Read more
Source§fn get_override(
&self,
experiment: &str,
actor: &str,
) -> Result<Option<String>, ExperimentStoreError>
fn get_override( &self, experiment: &str, actor: &str, ) -> Result<Option<String>, ExperimentStoreError>
Source§fn set_override(
&self,
experiment: &str,
actor: &str,
variant: &str,
) -> Result<(), ExperimentStoreError>
fn set_override( &self, experiment: &str, actor: &str, variant: &str, ) -> Result<(), ExperimentStoreError>
Source§fn has_assignment_in_group(
&self,
actor: &str,
group: &str,
exclude_experiment: &str,
) -> Result<bool, ExperimentStoreError>
fn has_assignment_in_group( &self, actor: &str, group: &str, exclude_experiment: &str, ) -> Result<bool, ExperimentStoreError>
Return
true if actor has an existing assignment in any experiment
belonging to group, excluding exclude_experiment itself. Read moreSource§fn history(
&self,
experiment: &str,
limit: usize,
) -> Result<Vec<ChangeRecord>, ExperimentStoreError>
fn history( &self, experiment: &str, limit: usize, ) -> Result<Vec<ChangeRecord>, ExperimentStoreError>
Return the change log for
experiment (most-recent first), capped at
limit entries. Returns an empty Vec for unknown experiments. Read moreAuto Trait Implementations§
impl !Freeze for PgExperimentStore
impl RefUnwindSafe for PgExperimentStore
impl Send for PgExperimentStore
impl Sync for PgExperimentStore
impl Unpin for PgExperimentStore
impl UnsafeUnpin for PgExperimentStore
impl UnwindSafe for PgExperimentStore
Blanket Implementations§
Source§impl<T> AggregateExpressionMethods for T
impl<T> AggregateExpressionMethods for T
Source§fn aggregate_distinct(self) -> Self::Outputwhere
Self: DistinctDsl,
fn aggregate_distinct(self) -> Self::Outputwhere
Self: DistinctDsl,
DISTINCT modifier for aggregate functions Read moreSource§fn aggregate_all(self) -> Self::Outputwhere
Self: AllDsl,
fn aggregate_all(self) -> Self::Outputwhere
Self: AllDsl,
ALL modifier for aggregate functions Read moreSource§fn aggregate_filter<P>(self, f: P) -> Self::Output
fn aggregate_filter<P>(self, f: P) -> Self::Output
Add an aggregate function filter Read more
Source§fn aggregate_order<O>(self, o: O) -> Self::Outputwhere
Self: OrderAggregateDsl<O>,
fn aggregate_order<O>(self, o: O) -> Self::Outputwhere
Self: OrderAggregateDsl<O>,
Add an aggregate function order Read more
Source§impl<T> AutumnDependents for Twhere
T: ?Sized,
impl<T> AutumnDependents for Twhere
T: ?Sized,
Source§fn dependents() -> &'static [RuntimeDependentSpec]
fn dependents() -> &'static [RuntimeDependentSpec]
The model’s dependent-cascade specs, in declaration order. Defaults to
none;
#[model] overrides via an inherent shadow when dependents exist.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
Mutably borrows from an owned value. Read more
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
Source§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Converts
Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>, which can then be
downcast into Box<dyn ConcreteType> where ConcreteType implements Trait.Source§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Converts
Rc<Trait> (where Trait: Downcast) to Rc<Any>, which can then be further
downcast into Rc<ConcreteType> where ConcreteType implements Trait.Source§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
Converts
&Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &Any’s vtable from &Trait’s.Source§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
Converts
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.Source§impl<T> DowncastSend for T
impl<T> DowncastSend for T
Source§impl<T> DowncastSync for T
impl<T> DowncastSync for T
impl<A, B, T> HttpServerConnExec<A, B> for Twhere
B: Body,
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> IntoSql for T
impl<T> IntoSql for T
Source§fn into_sql<T>(self) -> Self::Expression
fn into_sql<T>(self) -> Self::Expression
Convert
self to an expression for Diesel’s query builder. Read moreSource§fn as_sql<'a, T>(&'a self) -> <&'a Self as AsExpression<T>>::Expression
fn as_sql<'a, T>(&'a self) -> <&'a Self as AsExpression<T>>::Expression
Convert
&self to an expression for Diesel’s query builder. Read moreSource§impl<T> Pointable for T
impl<T> Pointable for T
Source§impl<T> PolicyExt for Twhere
T: ?Sized,
impl<T> PolicyExt for Twhere
T: ?Sized,
impl<T> Read<Exclusive, BecauseExclusive> for Twhere
T: ?Sized,
Source§impl<T> RepositoryHooksClone for Twhere
T: Clone,
impl<T> RepositoryHooksClone for Twhere
T: Clone,
Source§fn autumn_clone(&self) -> T
fn autumn_clone(&self) -> T
Clone hook state for generated repository values.
Source§impl<T, Conn> RunQueryDsl<Conn> for T
impl<T, Conn> RunQueryDsl<Conn> for T
Source§fn execute<'conn, 'query>(
self,
conn: &'conn mut Conn,
) -> <Conn as AsyncConnectionCore>::ExecuteFuture<'conn, 'query>
fn execute<'conn, 'query>( self, conn: &'conn mut Conn, ) -> <Conn as AsyncConnectionCore>::ExecuteFuture<'conn, 'query>
Executes the given command, returning the number of rows affected. Read more
Source§fn load<'query, 'conn, U>(
self,
conn: &'conn mut Conn,
) -> AndThen<Self::LoadFuture<'conn>, TryCollect<Self::Stream<'conn>, Vec<U>>>
fn load<'query, 'conn, U>( self, conn: &'conn mut Conn, ) -> AndThen<Self::LoadFuture<'conn>, TryCollect<Self::Stream<'conn>, Vec<U>>>
Source§fn load_stream<'conn, 'query, U>(
self,
conn: &'conn mut Conn,
) -> Self::LoadFuture<'conn>where
Conn: AsyncConnectionCore,
U: 'conn,
Self: LoadQuery<'query, Conn, U> + 'query,
fn load_stream<'conn, 'query, U>(
self,
conn: &'conn mut Conn,
) -> Self::LoadFuture<'conn>where
Conn: AsyncConnectionCore,
U: 'conn,
Self: LoadQuery<'query, Conn, U> + 'query,
Executes the given query, returning a [
Stream] with the returned rows. Read moreSource§fn get_result<'query, 'conn, U>(
self,
conn: &'conn mut Conn,
) -> AndThen<Self::LoadFuture<'conn>, LoadNext<Pin<Box<Self::Stream<'conn>>>>>
fn get_result<'query, 'conn, U>( self, conn: &'conn mut Conn, ) -> AndThen<Self::LoadFuture<'conn>, LoadNext<Pin<Box<Self::Stream<'conn>>>>>
Runs the command, and returns the affected row. Read more
Source§fn get_results<'query, 'conn, U>(
self,
conn: &'conn mut Conn,
) -> AndThen<Self::LoadFuture<'conn>, TryCollect<Self::Stream<'conn>, Vec<U>>>
fn get_results<'query, 'conn, U>( self, conn: &'conn mut Conn, ) -> AndThen<Self::LoadFuture<'conn>, TryCollect<Self::Stream<'conn>, Vec<U>>>
Runs the command, returning an
Vec with the affected rows. Read moreSource§impl<T> Scoped for T
impl<T> Scoped for T
Source§fn scope(ctx: &PolicyContext) -> ScopeQuery<'_, Self>
fn scope(ctx: &PolicyContext) -> ScopeQuery<'_, Self>
Open a deferred
ScopeQuery for this type. Resolves the
registered scope at .load() time, not here.Source§impl<T> WindowExpressionMethods for T
impl<T> WindowExpressionMethods for T
Source§fn over(self) -> Self::Outputwhere
Self: OverDsl,
fn over(self) -> Self::Outputwhere
Self: OverDsl,
Turn a function call into a window function call Read more
Source§fn window_filter<P>(self, f: P) -> Self::Output
fn window_filter<P>(self, f: P) -> Self::Output
Add a filter to the current window function Read more
Source§fn partition_by<E>(self, expr: E) -> Self::Outputwhere
Self: PartitionByDsl<E>,
fn partition_by<E>(self, expr: E) -> Self::Outputwhere
Self: PartitionByDsl<E>,
Add a partition clause to the current window function Read more
Source§fn window_order<E>(self, expr: E) -> Self::Outputwhere
Self: OrderWindowDsl<E>,
fn window_order<E>(self, expr: E) -> Self::Outputwhere
Self: OrderWindowDsl<E>,
Add a order clause to the current window function Read more