Skip to main content

EffectHandler

Trait EffectHandler 

Source
pub trait EffectHandler:
    Send
    + Sync
    + 'static {
    type Input: Serialize + DeserializeOwned + Send + Sync + 'static;
    type Output: Serialize + DeserializeOwned + Send + 'static;
    type Error: Into<EffectFailure> + Send + 'static;

    const NAME: &'static str;

    // Required method
    fn execute(
        &self,
        ctx: &EffectContext,
        input: &Self::Input,
    ) -> impl Future<Output = Result<Self::Output, Self::Error>> + Send;

    // Provided methods
    fn kind(&self) -> EffectKind { ... }
    fn remote_idempotency(&self) -> bool { ... }
    fn contract_version(&self) -> &str { ... }
    fn adapter_identity(&self) -> Option<&str> { ... }
    fn input_schema(&self) -> PayloadSchema { ... }
    fn output_schema(&self) -> PayloadSchema { ... }
    fn retry_policy(&self) -> Option<RetryPolicy> { ... }
    fn attempt_timeout(&self) -> Option<Duration> { ... }
    fn risk(&self) -> RiskLevel { ... }
    fn requires_approval(&self) -> bool { ... }
    fn precondition(
        &self,
        ctx: &EffectContext,
        input: &Self::Input,
    ) -> impl Future<Output = Precondition> + Send { ... }
}
Expand description

An effect the runtime can execute, and re-execute after a crash, from its stored input.

Implement execute; override the other methods to describe the effect. The defaults are the most cautious choices.

Required Associated Constants§

Source

const NAME: &'static str

The effect’s name, e.g. payment.charge. One handler per name.

Required Associated Types§

Source

type Input: Serialize + DeserializeOwned + Send + Sync + 'static

What the effect acts on. Stored with the record so recovery can rebuild the call: keep credentials in the handler, not here.

Source

type Output: Serialize + DeserializeOwned + Send + 'static

What the effect produces. Stored and replayed to later callers.

Source

type Error: Into<EffectFailure> + Send + 'static

The handler’s error, classified for the runtime.

Required Methods§

Source

fn execute( &self, ctx: &EffectContext, input: &Self::Input, ) -> impl Future<Output = Result<Self::Output, Self::Error>> + Send

Performs the effect once.

Provided Methods§

Source

fn kind(&self) -> EffectKind

What re-executing does to the outside world. Defaults to EffectKind::IrreversibleWrite.

Source

fn remote_idempotency(&self) -> bool

Whether the remote system deduplicates on EffectContext::idempotency_key, which execute must send.

Source

fn contract_version(&self) -> &str

Application-defined execution semantics version. Keep it stable for compatible releases; changes refuse existing keys before execution.

Source

fn adapter_identity(&self) -> Option<&str>

Optional trusted adapter/provider identity (never credentials).

Source

fn input_schema(&self) -> PayloadSchema

Schema written for new durable inputs and migrations used by recovery.

Source

fn output_schema(&self) -> PayloadSchema

Schema written for outputs and migrations used on committed replay.

Source

fn retry_policy(&self) -> Option<RetryPolicy>

The retry policy; None uses the runtime’s.

Source

fn attempt_timeout(&self) -> Option<Duration>

How long to wait for one attempt; None waits indefinitely.

Source

fn risk(&self) -> RiskLevel

How much damage the effect could do; see RiskPolicy. Defaults to RiskLevel::Low.

Source

fn requires_approval(&self) -> bool

Whether a human must approve the effect before its first attempt; see approval.

Source

fn precondition( &self, ctx: &EffectContext, input: &Self::Input, ) -> impl Future<Output = Precondition> + Send

Checked before the first attempt; see EffectBuilder::precondition.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§