Skip to main content

Event

Struct Event 

Source
pub struct Event<PT> {
    pub id: EventId,
    pub idempotency_token: Option<IdempotencyToken>,
    pub event_type: EventType,
    pub payload: Payload<PT>,
    pub created_at: OffsetDateTime,
    pub locked_until: OffsetDateTime,
    pub status: EventStatus,
}
Expand description

A single outbox row representing one domain event to be published.

An event starts out with status set to EventStatus::Pending and travels through the worker loop: a worker flips the row to EventStatus::Processing with a lock until locked_until, publishes via the transport, and finally marks it EventStatus::Sent. If a worker crashes, the lock expires and the row becomes eligible again.

Generic over the user’s payload type PT; see Payload.

Fields§

§id: EventId

Randomly generated primary key (UUID v4). Used to identify the row across status transitions.

§idempotency_token: Option<IdempotencyToken>

Deduplication token produced according to the configured IdempotencyStrategy. May be None when no token is produced.

§event_type: EventType

Domain-level event name used for routing on the transport side.

§payload: Payload<PT>

The user payload, serialized as JSON when the sqlx feature is on.

§created_at: OffsetDateTime

Wall-clock time the row was constructed, in UTC.

§locked_until: OffsetDateTime

Expiration of the current processing lock. Fresh rows start with OffsetDateTime::UNIX_EPOCH (i.e. “not locked”); storage adapters update this when they claim the row for processing.

§status: EventStatus

Current lifecycle stage. See EventStatus.

Implementations§

Source§

impl<PT> Event<PT>
where PT: Debug + Clone + Serialize,

Source

pub fn new( event_type: EventType, payload: Payload<PT>, idempotency_token: Option<IdempotencyToken>, ) -> Self

Constructs a new Event ready to be inserted by the storage layer.

The caller supplies the domain-level fields (event_type, payload, idempotency_token); the remaining fields are initialised with sensible defaults:

Trait Implementations§

Source§

impl<PT: Clone> Clone for Event<PT>

Source§

fn clone(&self) -> Event<PT>

Returns a duplicate of the value. Read more
1.0.0 · Source§

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

Performs copy-assignment from source. Read more
Source§

impl<PT: Debug> Debug for Event<PT>

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<PT> Freeze for Event<PT>
where PT: Freeze,

§

impl<PT> RefUnwindSafe for Event<PT>
where PT: RefUnwindSafe,

§

impl<PT> Send for Event<PT>
where PT: Send,

§

impl<PT> Sync for Event<PT>
where PT: Sync,

§

impl<PT> Unpin for Event<PT>
where PT: Unpin,

§

impl<PT> UnsafeUnpin for Event<PT>
where PT: UnsafeUnpin,

§

impl<PT> UnwindSafe for Event<PT>
where PT: UnwindSafe,

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