use crate::plugin::PluginError;
use super::events::{
ProcessAwaitOutput, ProcessEvent, ProcessEventAppendRequest, ProcessEventAppendResult,
};
use super::model::{
ProcessExternalRef, ProcessHandleDescriptor, ProcessHandleGrant, ProcessHandleGrantEntry,
ProcessLease, ProcessLeaseCompletion, ProcessRecord, ProcessRegistration, ProcessScope,
ProcessSessionDeleteReport,
};
#[async_trait::async_trait]
pub trait ProcessRegistry: Send + Sync {
fn durability_tier(&self) -> crate::DurabilityTier {
crate::DurabilityTier::Inline
}
async fn register_process(
&self,
registration: ProcessRegistration,
) -> Result<ProcessRecord, PluginError>;
async fn set_external_ref(
&self,
process_id: &str,
external_ref: ProcessExternalRef,
) -> Result<ProcessRecord, PluginError>;
async fn grant_handle(
&self,
owner_scope: &ProcessScope,
process_id: &str,
descriptor: ProcessHandleDescriptor,
) -> Result<ProcessHandleGrant, PluginError>;
async fn revoke_handle(
&self,
owner_scope: &ProcessScope,
process_id: &str,
) -> Result<(), PluginError>;
async fn transfer_handle_grants(
&self,
from_scope: &ProcessScope,
to_scope: &ProcessScope,
process_ids: &[String],
) -> Result<(), PluginError>;
async fn list_handle_grants(
&self,
owner_scope: &ProcessScope,
) -> Result<Vec<ProcessHandleGrantEntry>, PluginError>;
async fn list_live_handle_grants(
&self,
owner_scope: &ProcessScope,
) -> Result<Vec<ProcessHandleGrantEntry>, PluginError> {
Ok(self
.list_handle_grants(owner_scope)
.await?
.into_iter()
.filter(|(_, record)| !record.is_terminal())
.collect())
}
async fn has_handle_grant(
&self,
owner_scope: &ProcessScope,
process_id: &str,
) -> Result<bool, PluginError> {
Ok(self
.list_handle_grants(owner_scope)
.await?
.into_iter()
.any(|(grant, _)| grant.process_id == process_id))
}
async fn handle_grants_for_process(
&self,
process_id: &str,
) -> Result<Vec<ProcessHandleGrant>, PluginError>;
async fn delete_session_process_state(
&self,
session_id: &str,
) -> Result<ProcessSessionDeleteReport, PluginError>;
async fn append_event(
&self,
process_id: &str,
request: ProcessEventAppendRequest,
) -> Result<ProcessEventAppendResult, PluginError>;
async fn events_after(
&self,
process_id: &str,
after_sequence: u64,
) -> Result<Vec<ProcessEvent>, PluginError>;
async fn wake_events_after(
&self,
process_id: &str,
after_sequence: u64,
) -> Result<Vec<ProcessEvent>, PluginError>;
async fn wait_event_after(
&self,
process_id: &str,
event_type: &str,
after_sequence: u64,
) -> Result<ProcessEvent, PluginError>;
async fn await_process(&self, process_id: &str) -> Result<ProcessAwaitOutput, PluginError>;
async fn complete_process(
&self,
process_id: &str,
await_output: ProcessAwaitOutput,
) -> Result<ProcessRecord, PluginError>;
async fn get_process(&self, process_id: &str) -> Option<ProcessRecord>;
async fn ack_wake(&self, process_id: &str, sequence: u64) -> Result<(), PluginError>;
async fn list_non_terminal(&self) -> Result<Vec<ProcessRecord>, PluginError>;
async fn claim_process_lease(
&self,
process_id: &str,
owner_id: &str,
lease_ttl_ms: u64,
) -> Result<ProcessLease, PluginError>;
async fn renew_process_lease(
&self,
lease: &ProcessLease,
lease_ttl_ms: u64,
) -> Result<ProcessLease, PluginError>;
async fn complete_process_lease(
&self,
completion: &ProcessLeaseCompletion,
) -> Result<(), PluginError>;
}