Skip to main content

StateBackend

Trait StateBackend 

Source
pub trait StateBackend: Send + Sync {
Show 27 methods // Required methods fn store_workflow<'life0, 'async_trait>( &'life0 self, def: WorkflowDefinition, ) -> Pin<Box<dyn Future<Output = BackendResult<()>> + Send + 'async_trait>> where Self: 'async_trait, 'life0: 'async_trait; fn get_workflow<'life0, 'life1, 'life2, 'async_trait>( &'life0 self, workflow_id: &'life1 str, version: &'life2 str, ) -> Pin<Box<dyn Future<Output = BackendResult<Option<WorkflowDefinition>>> + Send + 'async_trait>> where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait; fn create_execution<'life0, 'async_trait>( &'life0 self, execution: WorkflowExecution, ) -> Pin<Box<dyn Future<Output = BackendResult<()>> + Send + 'async_trait>> where Self: 'async_trait, 'life0: 'async_trait; fn get_execution<'life0, 'life1, 'async_trait>( &'life0 self, id: &'life1 ExecutionId, ) -> Pin<Box<dyn Future<Output = BackendResult<Option<WorkflowExecution>>> + Send + 'async_trait>> where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait; fn update_execution_status<'life0, 'life1, 'async_trait>( &'life0 self, id: &'life1 ExecutionId, status: WorkflowStatus, ) -> Pin<Box<dyn Future<Output = BackendResult<()>> + Send + 'async_trait>> where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait; fn update_execution_current_state<'life0, 'life1, 'life2, 'async_trait>( &'life0 self, id: &'life1 ExecutionId, current_state: &'life2 Value, ) -> Pin<Box<dyn Future<Output = BackendResult<()>> + Send + 'async_trait>> where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait; fn patch_append_array<'life0, 'life1, 'life2, 'async_trait>( &'life0 self, execution_id: &'life1 ExecutionId, key: &'life2 str, value: Value, ) -> Pin<Box<dyn Future<Output = BackendResult<()>> + Send + 'async_trait>> where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait; fn list_executions<'life0, 'async_trait>( &'life0 self, status: Option<WorkflowStatus>, limit: u32, offset: u32, ) -> Pin<Box<dyn Future<Output = BackendResult<Vec<WorkflowExecution>>> + Send + 'async_trait>> where Self: 'async_trait, 'life0: 'async_trait; fn append_event<'life0, 'async_trait>( &'life0 self, event: Event, ) -> Pin<Box<dyn Future<Output = BackendResult<EventSequence>> + Send + 'async_trait>> where Self: 'async_trait, 'life0: 'async_trait; fn get_events<'life0, 'life1, 'async_trait>( &'life0 self, execution_id: &'life1 ExecutionId, ) -> Pin<Box<dyn Future<Output = BackendResult<Vec<Event>>> + Send + 'async_trait>> where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait; fn get_events_since<'life0, 'life1, 'async_trait>( &'life0 self, execution_id: &'life1 ExecutionId, since_sequence: EventSequence, ) -> Pin<Box<dyn Future<Output = BackendResult<Vec<Event>>> + Send + 'async_trait>> where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait; fn latest_sequence<'life0, 'life1, 'async_trait>( &'life0 self, execution_id: &'life1 ExecutionId, ) -> Pin<Box<dyn Future<Output = BackendResult<EventSequence>> + Send + 'async_trait>> where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait; fn write_snapshot<'life0, 'async_trait>( &'life0 self, snapshot: Snapshot, ) -> Pin<Box<dyn Future<Output = BackendResult<()>> + Send + 'async_trait>> where Self: 'async_trait, 'life0: 'async_trait; fn latest_snapshot<'life0, 'life1, 'async_trait>( &'life0 self, execution_id: &'life1 ExecutionId, ) -> Pin<Box<dyn Future<Output = BackendResult<Option<Snapshot>>> + Send + 'async_trait>> where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait; fn enqueue_work_item<'life0, 'async_trait>( &'life0 self, item: WorkItem, ) -> Pin<Box<dyn Future<Output = BackendResult<WorkItemId>> + Send + 'async_trait>> where Self: 'async_trait, 'life0: 'async_trait; fn claim_work_item<'life0, 'life1, 'life2, 'life3, 'async_trait>( &'life0 self, worker_id: &'life1 str, queue_types: &'life2 [&'life3 str], ) -> Pin<Box<dyn Future<Output = BackendResult<Option<WorkItem>>> + Send + 'async_trait>> where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait, 'life3: 'async_trait; fn renew_lease<'life0, 'life1, 'async_trait>( &'life0 self, item_id: WorkItemId, worker_id: &'life1 str, ) -> Pin<Box<dyn Future<Output = BackendResult<()>> + Send + 'async_trait>> where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait; fn complete_work_item<'life0, 'async_trait>( &'life0 self, item_id: WorkItemId, ) -> Pin<Box<dyn Future<Output = BackendResult<()>> + Send + 'async_trait>> where Self: 'async_trait, 'life0: 'async_trait; fn fail_work_item<'life0, 'life1, 'async_trait>( &'life0 self, item_id: WorkItemId, error: &'life1 str, ) -> Pin<Box<dyn Future<Output = BackendResult<()>> + Send + 'async_trait>> where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait; fn reclaim_expired_leases<'life0, 'async_trait>( &'life0 self, ) -> Pin<Box<dyn Future<Output = BackendResult<ReclaimResult>> + Send + 'async_trait>> where Self: 'async_trait, 'life0: 'async_trait; fn move_to_dead_letter<'life0, 'life1, 'async_trait>( &'life0 self, item_id: WorkItemId, last_error: &'life1 str, ) -> Pin<Box<dyn Future<Output = BackendResult<()>> + Send + 'async_trait>> where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait; fn create_token<'life0, 'life1, 'life2, 'async_trait>( &'life0 self, name: &'life1 str, role: &'life2 str, ) -> Pin<Box<dyn Future<Output = BackendResult<(String, ApiToken)>> + Send + 'async_trait>> where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait; fn validate_token<'life0, 'life1, 'async_trait>( &'life0 self, token: &'life1 str, ) -> Pin<Box<dyn Future<Output = BackendResult<Option<ApiToken>>> + Send + 'async_trait>> where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait; // Provided methods fn create_tenant<'life0, 'async_trait>( &'life0 self, _tenant: Tenant, ) -> Pin<Box<dyn Future<Output = BackendResult<()>> + Send + 'async_trait>> where Self: 'async_trait, 'life0: 'async_trait { ... } fn get_tenant<'life0, 'life1, 'async_trait>( &'life0 self, _id: &'life1 TenantId, ) -> Pin<Box<dyn Future<Output = BackendResult<Option<Tenant>>> + Send + 'async_trait>> where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait { ... } fn list_tenants<'life0, 'async_trait>( &'life0 self, ) -> Pin<Box<dyn Future<Output = BackendResult<Vec<Tenant>>> + Send + 'async_trait>> where Self: 'async_trait, 'life0: 'async_trait { ... } fn update_tenant<'life0, 'async_trait>( &'life0 self, _tenant: Tenant, ) -> Pin<Box<dyn Future<Output = BackendResult<()>> + Send + 'async_trait>> where Self: 'async_trait, 'life0: 'async_trait { ... }
}
Expand description

Trait abstracting the durable state storage backend.

Implementors: SqliteBackend, PostgresBackend. Both must guarantee transactional writes per state transition.

Required Methods§

Source

fn store_workflow<'life0, 'async_trait>( &'life0 self, def: WorkflowDefinition, ) -> Pin<Box<dyn Future<Output = BackendResult<()>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Store a compiled workflow IR.

Source

fn get_workflow<'life0, 'life1, 'life2, 'async_trait>( &'life0 self, workflow_id: &'life1 str, version: &'life2 str, ) -> Pin<Box<dyn Future<Output = BackendResult<Option<WorkflowDefinition>>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait,

Load a workflow definition by id and version.

Source

fn create_execution<'life0, 'async_trait>( &'life0 self, execution: WorkflowExecution, ) -> Pin<Box<dyn Future<Output = BackendResult<()>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Create a new workflow execution record.

Source

fn get_execution<'life0, 'life1, 'async_trait>( &'life0 self, id: &'life1 ExecutionId, ) -> Pin<Box<dyn Future<Output = BackendResult<Option<WorkflowExecution>>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Load a workflow execution by id.

Source

fn update_execution_status<'life0, 'life1, 'async_trait>( &'life0 self, id: &'life1 ExecutionId, status: WorkflowStatus, ) -> Pin<Box<dyn Future<Output = BackendResult<()>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Update the status of a workflow execution.

Source

fn update_execution_current_state<'life0, 'life1, 'life2, 'async_trait>( &'life0 self, id: &'life1 ExecutionId, current_state: &'life2 Value, ) -> Pin<Box<dyn Future<Output = BackendResult<()>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait,

Update the current_state of a workflow execution (apply state patches).

Source

fn patch_append_array<'life0, 'life1, 'life2, 'async_trait>( &'life0 self, execution_id: &'life1 ExecutionId, key: &'life2 str, value: Value, ) -> Pin<Box<dyn Future<Output = BackendResult<()>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait,

Append a value to an array field in the execution’s current_state. Creates the array if it doesn’t exist.

Source

fn list_executions<'life0, 'async_trait>( &'life0 self, status: Option<WorkflowStatus>, limit: u32, offset: u32, ) -> Pin<Box<dyn Future<Output = BackendResult<Vec<WorkflowExecution>>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

List executions, optionally filtered by status.

Source

fn append_event<'life0, 'async_trait>( &'life0 self, event: Event, ) -> Pin<Box<dyn Future<Output = BackendResult<EventSequence>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Append an event to the event log. Must be transactional — either fully written or not at all.

Source

fn get_events<'life0, 'life1, 'async_trait>( &'life0 self, execution_id: &'life1 ExecutionId, ) -> Pin<Box<dyn Future<Output = BackendResult<Vec<Event>>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Load all events for an execution, ordered by sequence.

Source

fn get_events_since<'life0, 'life1, 'async_trait>( &'life0 self, execution_id: &'life1 ExecutionId, since_sequence: EventSequence, ) -> Pin<Box<dyn Future<Output = BackendResult<Vec<Event>>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Load events since a given sequence number (exclusive).

Source

fn latest_sequence<'life0, 'life1, 'async_trait>( &'life0 self, execution_id: &'life1 ExecutionId, ) -> Pin<Box<dyn Future<Output = BackendResult<EventSequence>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Get the latest event sequence for an execution.

Source

fn write_snapshot<'life0, 'async_trait>( &'life0 self, snapshot: Snapshot, ) -> Pin<Box<dyn Future<Output = BackendResult<()>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Write a snapshot.

Source

fn latest_snapshot<'life0, 'life1, 'async_trait>( &'life0 self, execution_id: &'life1 ExecutionId, ) -> Pin<Box<dyn Future<Output = BackendResult<Option<Snapshot>>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Load the latest snapshot for an execution.

Source

fn enqueue_work_item<'life0, 'async_trait>( &'life0 self, item: WorkItem, ) -> Pin<Box<dyn Future<Output = BackendResult<WorkItemId>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Enqueue a work item for execution.

Source

fn claim_work_item<'life0, 'life1, 'life2, 'life3, 'async_trait>( &'life0 self, worker_id: &'life1 str, queue_types: &'life2 [&'life3 str], ) -> Pin<Box<dyn Future<Output = BackendResult<Option<WorkItem>>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait, 'life3: 'async_trait,

Claim the next available work item for a given queue type. Returns None if no items are available.

Source

fn renew_lease<'life0, 'life1, 'async_trait>( &'life0 self, item_id: WorkItemId, worker_id: &'life1 str, ) -> Pin<Box<dyn Future<Output = BackendResult<()>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Renew the lease on a claimed work item (heartbeat).

Source

fn complete_work_item<'life0, 'async_trait>( &'life0 self, item_id: WorkItemId, ) -> Pin<Box<dyn Future<Output = BackendResult<()>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Mark a work item as completed and release the lease.

Source

fn fail_work_item<'life0, 'life1, 'async_trait>( &'life0 self, item_id: WorkItemId, error: &'life1 str, ) -> Pin<Box<dyn Future<Output = BackendResult<()>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Mark a work item as failed. The scheduler will decide whether to retry.

Source

fn reclaim_expired_leases<'life0, 'async_trait>( &'life0 self, ) -> Pin<Box<dyn Future<Output = BackendResult<ReclaimResult>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Reclaim work items whose lease has expired (worker crashed or stalled).

For each expired item:

  • Increments attempt.
  • If attempt < max_attempts: resets to pending with optional backoff delay via retry_after, and returns it in the retryable list.
  • If attempt >= max_attempts: moves to dead_letter and returns it in the exhausted list.
Source

fn move_to_dead_letter<'life0, 'life1, 'async_trait>( &'life0 self, item_id: WorkItemId, last_error: &'life1 str, ) -> Pin<Box<dyn Future<Output = BackendResult<()>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Move a failed work item to the dead-letter queue.

Source

fn create_token<'life0, 'life1, 'life2, 'async_trait>( &'life0 self, name: &'life1 str, role: &'life2 str, ) -> Pin<Box<dyn Future<Output = BackendResult<(String, ApiToken)>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait,

Create a new API token. Returns (plaintext_token, token_info). The plaintext token is only returned here; only its hash is stored.

Source

fn validate_token<'life0, 'life1, 'async_trait>( &'life0 self, token: &'life1 str, ) -> Pin<Box<dyn Future<Output = BackendResult<Option<ApiToken>>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Validate a plaintext API token. Returns the token info if valid and not revoked.

Provided Methods§

Source

fn create_tenant<'life0, 'async_trait>( &'life0 self, _tenant: Tenant, ) -> Pin<Box<dyn Future<Output = BackendResult<()>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Create a new tenant.

Source

fn get_tenant<'life0, 'life1, 'async_trait>( &'life0 self, _id: &'life1 TenantId, ) -> Pin<Box<dyn Future<Output = BackendResult<Option<Tenant>>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Get a tenant by ID.

Source

fn list_tenants<'life0, 'async_trait>( &'life0 self, ) -> Pin<Box<dyn Future<Output = BackendResult<Vec<Tenant>>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

List all tenants.

Source

fn update_tenant<'life0, 'async_trait>( &'life0 self, _tenant: Tenant, ) -> Pin<Box<dyn Future<Output = BackendResult<()>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Update tenant metadata (name, status, policy, limits).

Dyn Compatibility§

This trait is dyn compatible.

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

Implementors§