pub struct EffectContext {
pub effect_id: Uuid,
pub workflow: WorkflowRef,
pub attempt: u32,
pub created_at: OffsetDateTime,
}Expand description
Context provided to effect handlers during execution.
Contains metadata for correlation (routing results back to the workflow) and idempotency (safe retries with external services).
§Idempotency
Use idempotency_key() when calling external APIs
that support idempotency keys. The key is stable across retries but unique
per effect instance.
§Example
async fn handle(&self, effect: &MyEffect, ctx: &EffectContext) -> Result<Option<MyInput>, MyError> {
// Use idempotency key for external API calls
let result = self.payment_client
.charge(amount, ctx.idempotency_key())
.await?;
// Use workflow_id for routing result back
Ok(Some(MyInput::PaymentResult {
order_id: ctx.workflow.workflow_id().to_string(),
success: result.success,
}))
}Fields§
§effect_id: UuidUnique identifier for this effect instance (UUID v7).
Used as the correlation ID for tracking and routing.
workflow: WorkflowRefThe workflow this effect belongs to.
attempt: u32Current attempt number (1-based).
First execution is attempt 1, first retry is attempt 2, etc.
created_at: OffsetDateTimeWhen this effect was first created/enqueued.
Implementations§
Source§impl EffectContext
impl EffectContext
Sourcepub fn new(
effect_id: Uuid,
workflow: WorkflowRef,
attempt: u32,
created_at: OffsetDateTime,
) -> Self
pub fn new( effect_id: Uuid, workflow: WorkflowRef, attempt: u32, created_at: OffsetDateTime, ) -> Self
Create a new effect context.
Sourcepub fn idempotency_key(&self) -> String
pub fn idempotency_key(&self) -> String
Get the idempotency key for external service calls.
Format: {workflow_type}:{workflow_id}:{effect_id}
This key is:
- Stable across retries — same key for all attempts of the same effect
- Unique per effect — different effects have different keys
Use this when calling APIs that support idempotency keys (Stripe, etc.).
Trait Implementations§
Source§impl Clone for EffectContext
impl Clone for EffectContext
Source§fn clone(&self) -> EffectContext
fn clone(&self) -> EffectContext
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreAuto Trait Implementations§
impl Freeze for EffectContext
impl RefUnwindSafe for EffectContext
impl Send for EffectContext
impl Sync for EffectContext
impl Unpin for EffectContext
impl UnwindSafe for EffectContext
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
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