#[non_exhaustive]pub struct WriteCtx {
pub correlation_id: String,
pub causation_id: Option<String>,
pub actor: Option<String>,
pub company_id: Option<Uuid>,
pub outbox_schema: Option<String>,
}Expand description
What a write hook knows about the write it runs in.
Fields (Non-exhaustive)§
This struct is marked as non-exhaustive
Struct { .. } syntax; cannot be matched against without a wildcard ..; and struct update syntax will not work.correlation_id: StringThe correlation id of the request (its x-correlation-id header, else the audit
attribution’s, else one minted for the write). Staged events carry it.
causation_id: Option<String>The id of the event, trigger or workflow step that caused this write, when one did.
Staged events carry it as their causation_id.
actor: Option<String>Who is writing: the request’s audit attribution; None for a job or an unscoped caller.
company_id: Option<Uuid>The company the request is scoped to, when it is. Events of an entity with no company of its own are staged under it.
outbox_schema: Option<String>The Postgres schema whose outbox_events table stage writes to, as the
hooks named it (WriteHooks::outbox_schema).
Implementations§
Source§impl WriteCtx
impl WriteCtx
Sourcepub fn current(outbox_schema: Option<&str>) -> Self
pub fn current(outbox_schema: Option<&str>) -> Self
The context of a write made now, in the current task.
Sourcepub fn company_or_nil(&self) -> Uuid
pub fn company_or_nil(&self) -> Uuid
The company to stage an event under when the entity names none: the request’s, else the nil uuid. The outbox table requires a value, and under org-unit tenancy the fence is the org unit the table fills from the acting unit, not this column.
Sourcepub fn company_of(&self, row: &Value) -> Uuid
pub fn company_of(&self, row: &Value) -> Uuid
The company an event of row is staged under: the row’s own company_id, else the
request’s, else the nil uuid.
Sourcepub async fn stage(&self, record: OutboxRecord) -> ServiceResult<()>
pub async fn stage(&self, record: OutboxRecord) -> ServiceResult<()>
Stage record on the write’s transaction. It commits with the write and vanishes if
the write rolls back. The record takes this context’s correlation id (and causation id)
unless it already carries one.
§Errors
A ServiceError when the hooks named no outbox schema, when no write transaction is
active (the repository has no pool, so the service ran the write without one), or when
the insert fails — which rolls the write back, since a write whose event cannot be staged
must not commit.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for WriteCtx
impl RefUnwindSafe for WriteCtx
impl Send for WriteCtx
impl Sync for WriteCtx
impl Unpin for WriteCtx
impl UnsafeUnpin for WriteCtx
impl UnwindSafe for WriteCtx
Blanket Implementations§
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
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> 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> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more