Skip to main content

Context

Struct Context 

Source
pub struct Context { /* private fields */ }
Expand description

Provides invocation metadata and staged durable changes to Step and RPC handlers.

A Context belongs to one handler attempt and must not outlive the call. Attribute writes, Channel publications, locals, and events become visible atomically only when the handler returns successfully. Application values are freshly decoded and owned by the invocation.

Implementations§

Source§

impl Context

Source

pub fn flow_id(&self) -> &str

Returns the application-assigned Flow ID.

Source

pub fn run_id(&self) -> &str

Returns the server-assigned run ID for this execution.

Source

pub fn flow_started_at(&self) -> SystemTime

Returns when the current Flow run started.

Source

pub fn step_execution_id(&self) -> &str

Returns the current Step execution ID, or an empty string for an RPC.

Source

pub fn from_step_execution_id(&self) -> &str

Returns the predecessor Step execution ID, or an empty string when absent.

Source

pub fn recovery_error(&self) -> Option<&RecoveryErrorInfo>

Returns the final failure that caused recovery, or None outside a recovery Step.

Source

pub fn first_attempt_at(&self) -> SystemTime

Returns when the first attempt of this handler invocation started.

Source

pub fn attempt(&self) -> u32

Returns the one-based handler attempt number.

Source

pub fn record_heartbeat(&mut self) -> HandlerResult<()>

Records a heartbeat without a Value and clears persisted heartbeat details.

The call blocks only while the Worker’s one-frame output buffer is full. It does not wait for Dex to process the heartbeat. Flow RPC Contexts reject this operation.

§Errors

Returns HandlerError for an RPC Context, cancellation, or a closed Worker response stream.

Source

pub fn record_heartbeat_value<T: Value>( &mut self, value: T, ) -> HandlerResult<()>

Records a heartbeat carrying a typed checkpoint Value.

A later regular attempt can decode the most recently accepted checkpoint with Self::last_heartbeat_value. Local activities accept the frame but do not persist it. The call uses the same bounded local buffering as Self::record_heartbeat.

§Examples
use dex_sdk::{Context, HandlerResult};
use serde::{Deserialize, Serialize};

#[derive(Deserialize, Serialize)]
struct Checkpoint {
    offset: u64,
}

fn import_batch(context: &mut Context, next_offset: u64) -> HandlerResult<()> {
    let previous = context.last_heartbeat_value::<Checkpoint>()?;
    let offset = previous.map_or(next_offset, |checkpoint| checkpoint.offset);
    context.record_heartbeat_value(Checkpoint { offset })
}
§Errors

Returns HandlerError for an RPC Context, encoding failure, cancellation, or a closed Worker response stream.

Source

pub fn last_heartbeat_value<T: Value>(&self) -> HandlerResult<Option<T>>

Decodes the checkpoint persisted by the previous regular attempt.

None means no heartbeat Value is present. To distinguish a null Value, request an optional application type: last_heartbeat_value::<Option<T>>() returns Some(None) for a present null Value.

§Errors

Returns HandlerError for an RPC Context or when the persisted Value cannot be decoded as T.

Source

pub fn has_any_timer_fired(&self) -> bool

Returns whether any timer condition completed for this execute invocation.

Source

pub fn has_timer_fired(&self, index: usize) -> bool

Returns whether the zero-based timer at index completed.

Missing indexes return false.

Source

pub fn wait_for_method_failed(&self) -> bool

Returns whether execute is running because wait_for exhausted retries with Proceed.

Source

pub fn wait_for_cancellation(&self)

Blocks the current thread until Dex cancels this handler attempt.

Use this only for interruptible application work; ordinary handlers should return normally.

Source

pub fn is_cancelled(&self) -> bool

Returns immediately with the current handler-cancellation state.

Source

pub fn set_step_execution_local<T: Value>( &mut self, key: &str, value: T, ) -> HandlerResult<()>

Stages a Step-execution-local value visible to later attempts of the same execution.

§Errors

Returns HandlerError for an empty key or an encoding failure.

Source

pub fn step_execution_local<T: Value>(&self, key: &str) -> HandlerResult<T>

Reads a required Step-execution-local value, including writes staged by this attempt.

§Errors

Returns HandlerError for an empty key, a missing value, or a decoding failure.

Source

pub fn record_event<T: Value>( &mut self, name: &str, value: T, ) -> HandlerResult<()>

Records one named diagnostic event with a typed payload.

Event names must be unique within the invocation.

§Errors

Returns HandlerError for an empty or duplicate name or an encoding failure.

Source

pub fn get_attribute<T: Value>( &self, attribute: &Attribute<T>, ) -> HandlerResult<Option<T>>

Reads an Attribute value, including writes staged by this invocation.

Source

pub fn get_attribute_map<T: Value>( &self, attribute: &AttributeMap<T>, instance: &str, ) -> HandlerResult<Option<T>>

Reads one Attribute-map instance, including staged writes.

Source

pub fn set_attribute<T: Value>( &mut self, attribute: &Attribute<T>, value: T, ) -> HandlerResult<()>

Stages a typed Attribute write.

Source

pub fn set_attribute_map<T: Value>( &mut self, attribute: &AttributeMap<T>, instance: &str, value: T, ) -> HandlerResult<()>

Stages a typed write for one Attribute-map instance.

Source

pub fn delete_attribute<T>( &mut self, attribute: &Attribute<T>, ) -> HandlerResult<()>

Stages deletion of an Attribute value.

Source

pub fn delete_attribute_map<T>( &mut self, attribute: &AttributeMap<T>, instance: &str, ) -> HandlerResult<()>

Stages deletion of one Attribute-map instance.

Source

pub fn publish<T: Value>( &mut self, channel: &Channel<T>, value: T, ) -> HandlerResult<()>

Stages one typed Channel publication.

Source

pub fn publish_map<T: Value>( &mut self, channel: &ChannelMap<T>, instance: &str, value: T, ) -> HandlerResult<()>

Stages one typed publication to a Channel-map instance.

Source

pub fn channel_size<T>(&self, channel: &Channel<T>) -> HandlerResult<usize>

Returns the current invocation snapshot’s Channel queue size.

Source

pub fn channel_map_size<T>( &self, channel: &ChannelMap<T>, instance: &str, ) -> HandlerResult<usize>

Returns one Channel-map instance’s queue size.

Source

pub fn pending_channel_messages<T: Value>( &self, channel: &Channel<T>, ) -> HandlerResult<Vec<ChannelMessage<T>>>

Returns one singleton Channel’s loaded pending-message snapshot.

Source

pub fn pending_channel_map_messages<T: Value>( &self, channel: &ChannelMap<T>, instance: &str, ) -> HandlerResult<Vec<ChannelMessage<T>>>

Returns one Channel-map instance’s loaded pending-message snapshot.

Source

pub fn channel_results<T: Value>( &self, channel: &Channel<T>, ) -> HandlerResult<Vec<T>>

Decodes the messages consumed by a satisfied Channel condition.

Source

pub fn channel_map_results<T: Value>( &self, channel: &ChannelMap<T>, instance: &str, ) -> HandlerResult<Vec<T>>

Decodes messages consumed by one satisfied Channel-map condition.

Source

pub fn write_stream<T: Value>( &mut self, stream: &Stream<T>, value: T, ) -> HandlerResult<()>

Appends one best-effort Stream message to the current Worker response stream.

The call returns after the Worker’s bounded output buffer accepts the frame. It does not wait for Dex or the Stream Store, and a later server-side write failure is not returned to the handler. One invocation may append any number of messages to the same Stream.

§Errors

Returns HandlerError for an RPC or Flow timeout Context, an unregistered Stream, a capacity mismatch, encoding failure, cancellation, or a closed Worker response stream.

Source

pub fn delete_channel_message<T>( &mut self, channel: &Channel<T>, message_id: &str, ) -> HandlerResult<()>

Stages best-effort deletion of one singleton Channel message.

Source

pub fn delete_channel_map_message<T>( &mut self, channel: &ChannelMap<T>, instance: &str, message_id: &str, ) -> HandlerResult<()>

Stages best-effort deletion of one Channel-map message.

Auto Trait Implementations§

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> 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> IntoRequest<T> for T

Source§

fn into_request(self) -> Request<T>

Wrap the input message T in a tonic::Request
Source§

impl<L> LayerExt<L> for L

Source§

fn named_layer<S>(&self, service: S) -> Layered<<L as Layer<S>>::Service, S>
where L: Layer<S>,

Applies the layer to a service and wraps it in Layered.
Source§

impl<T> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

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