Skip to main content

Executor

Trait Executor 

Source
pub trait Executor:
    Send
    + Sync
    + 'static {
    // Required methods
    fn write<'life0, 'async_trait>(
        &'life0 self,
        events: Vec<Event>,
    ) -> Pin<Box<dyn Future<Output = Result<(), WriteError>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait;
    fn get_subscriber_cursor<'life0, 'async_trait>(
        &'life0 self,
        key: String,
    ) -> Pin<Box<dyn Future<Output = Result<Option<Value>>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait;
    fn is_subscriber_running<'life0, 'async_trait>(
        &'life0 self,
        key: String,
        worker_id: Ulid,
    ) -> Pin<Box<dyn Future<Output = Result<bool>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait;
    fn upsert_subscriber<'life0, 'async_trait>(
        &'life0 self,
        key: String,
        worker_id: Ulid,
    ) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait;
    fn acknowledge<'life0, 'async_trait>(
        &'life0 self,
        key: String,
        cursor: Value,
        lag: u64,
    ) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait;
    fn read<'life0, 'async_trait>(
        &'life0 self,
        aggregators: Option<Vec<EventFilter>>,
        routing_key: Option<RoutingKey>,
        args: Args,
    ) -> Pin<Box<dyn Future<Output = Result<ReadResult<Event>>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait;
    fn latest_timestamp<'life0, 'async_trait>(
        &'life0 self,
        aggregators: Option<Vec<EventFilter>>,
        routing_key: Option<RoutingKey>,
    ) -> Pin<Box<dyn Future<Output = Result<u64>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait;
    fn get_snapshot<'life0, 'async_trait>(
        &'life0 self,
        aggregate_type: String,
        aggregate_revision: String,
        id: String,
    ) -> Pin<Box<dyn Future<Output = Result<Option<(Vec<u8>, Value)>>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait;
    fn save_snapshot<'life0, 'async_trait>(
        &'life0 self,
        aggregate_type: String,
        aggregate_revision: String,
        id: String,
        data: Vec<u8>,
        cursor: Value,
    ) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait;
    fn delete_snapshot<'life0, 'async_trait>(
        &'life0 self,
        aggregate_type: String,
        id: String,
    ) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait;

    // Provided method
    fn default_routing_key(&self) -> Option<&str> { ... }
}
Expand description

Core trait for event storage backends.

Implementations handle persisting events, querying, and managing subscriptions. The main implementation is evento_sql::Sql.

§Methods

  • write - Persist events atomically
  • read - Query events with filtering and pagination
  • latest_timestamp - Get the timestamp of the most recent matching event
  • get_subscriber_cursor - Get subscription position
  • is_subscriber_running - Check if subscription is active
  • upsert_subscriber - Create/update subscription
  • acknowledge - Update subscription cursor

Required Methods§

Source

fn write<'life0, 'async_trait>( &'life0 self, events: Vec<Event>, ) -> Pin<Box<dyn Future<Output = Result<(), WriteError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Persists events atomically.

Returns WriteError::InvalidOriginalVersion if version conflicts occur.

Source

fn get_subscriber_cursor<'life0, 'async_trait>( &'life0 self, key: String, ) -> Pin<Box<dyn Future<Output = Result<Option<Value>>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Gets the current cursor position for a subscription.

Source

fn is_subscriber_running<'life0, 'async_trait>( &'life0 self, key: String, worker_id: Ulid, ) -> Pin<Box<dyn Future<Output = Result<bool>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Checks if a subscription is running with the given worker ID.

Source

fn upsert_subscriber<'life0, 'async_trait>( &'life0 self, key: String, worker_id: Ulid, ) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Creates or updates a subscription record.

Source

fn acknowledge<'life0, 'async_trait>( &'life0 self, key: String, cursor: Value, lag: u64, ) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Updates subscription cursor after processing events.

Source

fn read<'life0, 'async_trait>( &'life0 self, aggregators: Option<Vec<EventFilter>>, routing_key: Option<RoutingKey>, args: Args, ) -> Pin<Box<dyn Future<Output = Result<ReadResult<Event>>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Queries events with filtering and pagination.

Source

fn latest_timestamp<'life0, 'async_trait>( &'life0 self, aggregators: Option<Vec<EventFilter>>, routing_key: Option<RoutingKey>, ) -> Pin<Box<dyn Future<Output = Result<u64>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Returns the timestamp of the most recent event matching the filter.

Returns 0 when no matching event exists. Used by the subscription loop to compute lag without fetching the full event row (data/metadata blobs).

Source

fn get_snapshot<'life0, 'async_trait>( &'life0 self, aggregate_type: String, aggregate_revision: String, id: String, ) -> Pin<Box<dyn Future<Output = Result<Option<(Vec<u8>, Value)>>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Retrieves a stored snapshot for an aggregate.

Returns the serialized snapshot data and cursor position, or None if no snapshot exists for the given aggregate.

Source

fn save_snapshot<'life0, 'async_trait>( &'life0 self, aggregate_type: String, aggregate_revision: String, id: String, data: Vec<u8>, cursor: Value, ) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Stores a snapshot for an aggregate.

Snapshots cache aggregate state to avoid replaying all events. The cursor indicates the event position up to which the snapshot is valid.

Source

fn delete_snapshot<'life0, 'async_trait>( &'life0 self, aggregate_type: String, id: String, ) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Deletes a stored snapshot for an aggregate.

Idempotent: deleting a snapshot that does not exist is not an error. Revision is intentionally omitted — save_snapshot upserts on (type, id) so there is only ever one row per aggregate.

Provided Methods§

Source

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

Default routing key applied to writes and inherited by subscriptions.

Most backends return None; Evento overrides this to expose its configured default. Used by Evento::write to fill in missing routing keys, and by SubscriptionBuilder::start / ProjectionSubscription::start to inherit a default when the user has not called .routing_key() or .all().

Dyn Compatibility§

This trait is dyn compatible.

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

Implementors§