Skip to main content

EffectRecord

Struct EffectRecord 

Source
pub struct EffectRecord {
Show 23 fields pub id: EffectId, pub key: EffectKey, pub kind: EffectKind, pub status: EffectStatus, pub input: Option<Value>, pub input_fingerprint: Option<String>, pub output: Option<Value>, pub last_error: Option<ErrorRecord>, pub created_by: Option<String>, pub attempt_count: u32, pub may_have_applied: bool, pub compensation_attempts: u32, pub approved: bool, pub next_attempt_at: Option<SystemTime>, pub attempt_started_at: Option<SystemTime>, pub attempt_ended_at: Option<SystemTime>, pub lease_owner: Option<WorkerId>, pub lease_epoch: u64, pub lease_expires_at: Option<SystemTime>, pub version: u64, pub created_at: SystemTime, pub updated_at: SystemTime, pub committed_at: Option<SystemTime>,
}
Expand description

The durable state of one effect.

The methods are pure: they check a change against the record and apply it in memory. Stores call them inside a transaction and persist the result, so the rules are the same for every backend.

Fields§

§id: EffectId

Record id.

§key: EffectKey

Logical identity, unique per store.

§kind: EffectKind

The effect’s kind.

§status: EffectStatus

Current status.

§input: Option<Value>

The input, redacted for storage.

§input_fingerprint: Option<String>

Hash of the unredacted input.

§output: Option<Value>

The latest action or verification result.

§last_error: Option<ErrorRecord>

The latest recorded failure.

§created_by: Option<String>

Who asked for the effect.

§attempt_count: u32

Attempts started so far.

§may_have_applied: bool

An attempt may have applied the effect, and no evidence has shown otherwise since. Set when an outcome becomes unknown; cleared only by a trusted verification or an operator. While it is set, the effect cannot become Failed through a failed attempt (see Self::apply).

§compensation_attempts: u32

Compensation attempts started so far.

§approved: bool

The effect was approved, so it is not asked again, even after a restart.

§next_attempt_at: Option<SystemTime>

When a scheduled retry may start.

§attempt_started_at: Option<SystemTime>

When the latest attempt started.

§attempt_ended_at: Option<SystemTime>

When the latest attempt was last known to be in flight: the first transition out of Executing after it started. Settle delays count from here.

§lease_owner: Option<WorkerId>

Current lease holder, if any. The lease may have expired.

§lease_epoch: u64

Fencing token; incremented by every lease acquisition.

§lease_expires_at: Option<SystemTime>

When the current lease lapses.

§version: u64

Incremented by every transition. Lease operations do not change it.

§created_at: SystemTime

Creation time.

§updated_at: SystemTime

Time of the latest change.

§committed_at: Option<SystemTime>

When the effect committed.

Implementations§

Source§

impl EffectRecord

Source

pub fn new(new: NewEffect) -> EffectRecord

A fresh Pending record.

Source

pub fn live_lease_owner(&self, now: SystemTime) -> Option<&WorkerId>

The holder of a lease that is still live at now.

Source

pub fn acquire_lease( &mut self, owner: &WorkerId, now: SystemTime, ttl: Duration, ) -> Result<Lease, StoreError>

Takes the lease for ttl, provided nobody holds a live one.

§Errors

StoreError::LeaseHeld if a live lease exists, even one held by owner: two tasks of one worker must not run the same effect either.

Source

pub fn renew_lease( &mut self, lease: &Lease, now: SystemTime, ttl: Duration, ) -> Result<Lease, StoreError>

Extends lease to now + ttl.

§Errors

StoreError::LeaseLost if the lease expired or was taken over. Renewal is strict: an expired lease cannot be revived, even if nobody else took it.

Source

pub fn release_lease(&mut self, lease: &Lease) -> bool

Clears lease if it is still the current one, expired or not. Returns whether anything changed.

Source

pub fn apply( &mut self, request: TransitionRequest, ) -> Result<EffectEvent, StoreError>

Applies request and returns the audit event to persist with it. On error the record is unchanged.

Checks, in order: the lease (or the absence of a live one), the version, and the transition table. Then it updates the bookkeeping:

  • Transition::StartAttempt increments the attempt count, stamps attempt_started_at, and clears attempt_ended_at and next_attempt_at; any transition out of Executing stamps attempt_ended_at;
  • Transition::StartCompensation sets compensation_attempts to 1 and Transition::StartCompensationRetry increments it; both clear next_attempt_at;
  • a retry transition, including Transition::ScheduleCompensationRetry, sets next_attempt_at (default now);
  • reaching Committed stamps committed_at;
  • reaching Unknown sets may_have_applied; evidence that the effect did not apply clears it (VerificationNotApplied, ResolvedNotApplied, or a ScheduleRetry out of Verifying, which the runtime issues only after a trusted “not applied”);
  • output and error, when given, replace the stored ones.

Failed must mean the effect did not apply. A failed attempt proves that only for itself, so FailedDefinitively is refused while may_have_applied is set (except for Read effects, which apply nothing).

§Errors

StoreError::LeaseLost, StoreError::LeaseHeld, StoreError::VersionConflict or StoreError::InvalidTransition.

Trait Implementations§

Source§

impl Clone for EffectRecord

Source§

fn clone(&self) -> EffectRecord

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for EffectRecord

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more
Source§

impl<'de> Deserialize<'de> for EffectRecord

Source§

fn deserialize<__D>( __deserializer: __D, ) -> Result<EffectRecord, <__D as Deserializer<'de>>::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl PartialEq for EffectRecord

Source§

fn eq(&self, other: &EffectRecord) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl Serialize for EffectRecord

Source§

fn serialize<__S>( &self, __serializer: __S, ) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

impl StructuralPartialEq for EffectRecord

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<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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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