Skip to main content

CommandRegistry

Trait CommandRegistry 

Source
pub trait CommandRegistry: Send + Sync {
    // Required methods
    fn resolve_target<'life0, 'life1, 'life2, 'async_trait>(
        &'life0 self,
        deployment_id: &'life1 str,
        requested: Option<&'life2 str>,
    ) -> Pin<Box<dyn Future<Output = Result<ResolvedCommandTarget>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait,
             'life2: 'async_trait;
    fn create_command<'life0, 'life1, 'life2, 'life3, 'async_trait>(
        &'life0 self,
        deployment_id: &'life1 str,
        command_name: &'life2 str,
        target: &'life3 ResolvedCommandTarget,
        initial_state: CommandState,
        deadline: Option<DateTime<Utc>>,
        request_size_bytes: Option<u64>,
    ) -> Pin<Box<dyn Future<Output = Result<CommandMetadata>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait,
             'life2: 'async_trait,
             'life3: 'async_trait;
    fn get_command_metadata<'life0, 'life1, 'async_trait>(
        &'life0 self,
        command_id: &'life1 str,
    ) -> Pin<Box<dyn Future<Output = Result<Option<CommandEnvelopeData>>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait;
    fn get_command_status<'life0, 'life1, 'async_trait>(
        &'life0 self,
        command_id: &'life1 str,
    ) -> Pin<Box<dyn Future<Output = Result<Option<CommandStatus>>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait;
    fn update_command_state<'life0, 'life1, 'async_trait>(
        &'life0 self,
        command_id: &'life1 str,
        state: CommandState,
        dispatched_at: Option<DateTime<Utc>>,
        completed_at: Option<DateTime<Utc>>,
        response_size_bytes: Option<u64>,
        error: Option<Value>,
    ) -> Pin<Box<dyn Future<Output = Result<bool>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait;
    fn complete_command<'life0, 'life1, 'async_trait>(
        &'life0 self,
        command_id: &'life1 str,
        state: CommandState,
        completed_at: DateTime<Utc>,
        response_size_bytes: Option<u64>,
        error: Option<Value>,
    ) -> Pin<Box<dyn Future<Output = Result<bool>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait;
    fn mark_dispatched_if_not_terminal<'life0, 'life1, 'async_trait>(
        &'life0 self,
        command_id: &'life1 str,
        dispatched_at: DateTime<Utc>,
    ) -> Pin<Box<dyn Future<Output = Result<bool>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait;
    fn increment_attempt<'life0, 'life1, 'async_trait>(
        &'life0 self,
        command_id: &'life1 str,
    ) -> Pin<Box<dyn Future<Output = Result<u32>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait;

    // Provided method
    fn get_command_access_context<'life0, 'life1, 'async_trait>(
        &'life0 self,
        command_id: &'life1 str,
    ) -> Pin<Box<dyn Future<Output = Result<Option<CommandAccessContext>>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait { ... }
}
Expand description

Abstraction for command metadata storage and lifecycle tracking.

The CommandRegistry is the source of truth for all command metadata. Implementations store command state, timestamps, and result information.

Required Methods§

Source

fn resolve_target<'life0, 'life1, 'life2, 'async_trait>( &'life0 self, deployment_id: &'life1 str, requested: Option<&'life2 str>, ) -> Pin<Box<dyn Future<Output = Result<ResolvedCommandTarget>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait,

Resolve which command-capable resource a command is addressed to.

  • requested = Some(id): the target must exist and be command-capable, else COMMAND_TARGET_NOT_FOUND (an empty id never resolves).
  • requested = None (single-target shorthand): exactly one command-capable target must exist, else COMMAND_TARGET_AMBIGUOUS (more than one) or NO_COMMAND_TARGETS (none).

The returned delivery mode is derived from the target: Container and Daemon targets are always Pull. Worker delivery is resolved from the deployment model and platform: Kubernetes uses its in-cluster operator relay, Local supports embedded Push and remote Pull, and cloud Workers use their provider push path only for Push deployments.

Source

fn create_command<'life0, 'life1, 'life2, 'life3, 'async_trait>( &'life0 self, deployment_id: &'life1 str, command_name: &'life2 str, target: &'life3 ResolvedCommandTarget, initial_state: CommandState, deadline: Option<DateTime<Utc>>, request_size_bytes: Option<u64>, ) -> Pin<Box<dyn Future<Output = Result<CommandMetadata>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait, 'life3: 'async_trait,

Create a new command addressed to a previously resolved target and return metadata for routing.

The registry generates the command_id and stores all metadata (state, target, timestamps, etc.).

Source

fn get_command_metadata<'life0, 'life1, 'async_trait>( &'life0 self, command_id: &'life1 str, ) -> Pin<Box<dyn Future<Output = Result<Option<CommandEnvelopeData>>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Get metadata needed to build an envelope during lease acquisition.

Returns None if command doesn’t exist.

Source

fn get_command_status<'life0, 'life1, 'async_trait>( &'life0 self, command_id: &'life1 str, ) -> Pin<Box<dyn Future<Output = Result<Option<CommandStatus>>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Get full command status for status endpoint.

Returns None if command doesn’t exist.

Source

fn update_command_state<'life0, 'life1, 'async_trait>( &'life0 self, command_id: &'life1 str, state: CommandState, dispatched_at: Option<DateTime<Utc>>, completed_at: Option<DateTime<Utc>>, response_size_bytes: Option<u64>, error: Option<Value>, ) -> Pin<Box<dyn Future<Output = Result<bool>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Atomically update a non-terminal command’s lifecycle state.

Returns false when the command became terminal before the update. Terminal transitions use Self::complete_command instead.

Source

fn complete_command<'life0, 'life1, 'async_trait>( &'life0 self, command_id: &'life1 str, state: CommandState, completed_at: DateTime<Utc>, response_size_bytes: Option<u64>, error: Option<Value>, ) -> Pin<Box<dyn Future<Output = Result<bool>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Atomically transition a command from any NON-terminal state to the given terminal state.

Returns false when the command was already terminal — a concurrent submitter won the race — so a terminal record can never be overwritten by a late duplicate (redelivered execution racing the original whose lease expired).

Source

fn mark_dispatched_if_not_terminal<'life0, 'life1, 'async_trait>( &'life0 self, command_id: &'life1 str, dispatched_at: DateTime<Utc>, ) -> Pin<Box<dyn Future<Output = Result<bool>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Atomically mark a command Dispatched unless it is already terminal.

Returns false when the command reached a terminal state in the meantime — e.g. a lease TTL-expired, a new poller won the takeover put, and the ORIGINAL holder’s submit landed between the poller’s terminal check and this write. An unconditional write there would flip a committed terminal state back to Dispatched.

Source

fn increment_attempt<'life0, 'life1, 'async_trait>( &'life0 self, command_id: &'life1 str, ) -> Pin<Box<dyn Future<Output = Result<u32>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Increment attempt count (on lease release/expiry).

Returns the new attempt number.

Provided Methods§

Source

fn get_command_access_context<'life0, 'life1, 'async_trait>( &'life0 self, command_id: &'life1 str, ) -> Pin<Box<dyn Future<Output = Result<Option<CommandAccessContext>>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Get the canonical ownership fields used to authorize command reads.

The status record is the command registry’s source of truth for these fields, so this does not require a deployment lookup.

Dyn Compatibility§

This trait is dyn compatible.

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

Implementors§