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 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§
Required Associated Types§
Sourcetype Input: Serialize + DeserializeOwned + Send + Sync + 'static
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.
Sourcetype Output: Serialize + DeserializeOwned + Send + 'static
type Output: Serialize + DeserializeOwned + Send + 'static
What the effect produces. Stored and replayed to later callers.
Sourcetype Error: Into<EffectFailure> + Send + 'static
type Error: Into<EffectFailure> + Send + 'static
The handler’s error, classified for the runtime.
Required Methods§
Provided Methods§
Sourcefn kind(&self) -> EffectKind
fn kind(&self) -> EffectKind
What re-executing does to the outside world. Defaults to
EffectKind::IrreversibleWrite.
Sourcefn remote_idempotency(&self) -> bool
fn remote_idempotency(&self) -> bool
Whether the remote system deduplicates on
EffectContext::idempotency_key, which execute must send.
Sourcefn retry_policy(&self) -> Option<RetryPolicy>
fn retry_policy(&self) -> Option<RetryPolicy>
The retry policy; None uses the runtime’s.
Sourcefn attempt_timeout(&self) -> Option<Duration>
fn attempt_timeout(&self) -> Option<Duration>
How long to wait for one attempt; None waits indefinitely.
Sourcefn risk(&self) -> RiskLevel
fn risk(&self) -> RiskLevel
How much damage the effect could do; see
RiskPolicy. Defaults to RiskLevel::Low.
Sourcefn requires_approval(&self) -> bool
fn requires_approval(&self) -> bool
Whether a human must approve the effect before its first attempt;
see approval.
Sourcefn precondition(
&self,
ctx: &EffectContext,
input: &Self::Input,
) -> impl Future<Output = Precondition> + Send
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".