pub struct TenantAwarePostgresTaskStore { /* private fields */ }Expand description
Tenant-scoped PostgreSQL-backed TaskStore.
Each operation is scoped to the tenant from TenantContext. Tasks are
stored with a tenant_id column for database-level isolation, enabling
efficient per-tenant queries and deletion.
Implementations§
Source§impl TenantAwarePostgresTaskStore
impl TenantAwarePostgresTaskStore
Sourcepub const fn with_max_page_size(self, max: u32) -> TenantAwarePostgresTaskStore
Available on crate feature postgres only.
pub const fn with_max_page_size(self, max: u32) -> TenantAwarePostgresTaskStore
postgres only.Caps the page size list returns, however large a page is asked for.
Defaults to DEFAULT_MAX_PAGE_SIZE, which explains why this store
needs its own knob rather than reading TaskStoreConfig.
Sourcepub fn with_metrics(
self,
metrics: MetricsHandle,
) -> TenantAwarePostgresTaskStore
Available on crate feature postgres only.
pub fn with_metrics( self, metrics: MetricsHandle, ) -> TenantAwarePostgresTaskStore
postgres only.Sets where this store reports an event it could not record.
Defaults to NoopMetrics. See
event_append_error: a
multi-replica deployment is what this store is for, and two replicas
numbering one task’s log is exactly what an append that writes nothing
reports.
Sourcepub fn with_log_notifications(
self,
listen: LogListen,
) -> TenantAwarePostgresTaskStore
Available on crate feature postgres only.
pub fn with_log_notifications( self, listen: LogListen, ) -> TenantAwarePostgresTaskStore
postgres only.Wakes a SubscribeToTask stream when an event is appended to its task’s
log, instead of when its timer next ends, as
PostgresTaskStore::with_log_notifications
does, whose text applies, including the advice to listen on a direct
connection (LogListen::Direct) behind
a connection pooler. A notification names the task and the tenant (and
caller) partition it is stored under, so a stream wakes only for its own
partition’s task.
Sourcepub async fn new(url: &str) -> Result<TenantAwarePostgresTaskStore, Error>
Available on crate feature postgres only.
pub async fn new(url: &str) -> Result<TenantAwarePostgresTaskStore, Error>
postgres only.Opens a PostgreSQL connection pool and initializes the schema.
§Errors
Returns an error if the database cannot be opened or migration fails.
Sourcepub async fn new_with_pool_size(
url: &str,
size: u32,
) -> Result<TenantAwarePostgresTaskStore, Error>
Available on crate feature postgres only.
pub async fn new_with_pool_size( url: &str, size: u32, ) -> Result<TenantAwarePostgresTaskStore, Error>
postgres only.new, with a pool of size connections instead of
DEFAULT_POOL_SIZE (10); zero is
read as one. The size is logged at INFO (feature tracing).
Every replica opens its own pools, so the sum of every pool size in a
replica, times the replicas (and a surge pod during a rollout), must
stay under the server’s max_connections: 100 by default, 3 of them
reserved for superusers (audit E-F6, D-17). The book’s Running More
Than One Replica gives the arithmetic.
§Errors
Returns an error if the database cannot be opened or the schema migration fails.
Sourcepub async fn from_pool(
pool: Pool<Postgres>,
) -> Result<TenantAwarePostgresTaskStore, Error>
Available on crate feature postgres only.
pub async fn from_pool( pool: Pool<Postgres>, ) -> Result<TenantAwarePostgresTaskStore, Error>
postgres only.Creates a store from an existing connection pool.
The pool keeps its own settings; for the ones new
uses, build it from
PostgresTaskStore::pool_options,
which says what else may share it.
§Errors
Returns an error if the schema migration fails.
Sourcepub async fn purge_expired(
&self,
policy: &RetentionPolicy,
) -> Result<PurgeReport, A2aError>
Available on crate feature postgres only.
pub async fn purge_expired( &self, policy: &RetentionPolicy, ) -> Result<PurgeReport, A2aError>
postgres only.Deletes terminal tasks that have outlived policy.
Nothing calls this for you. A persistent store keeps every task until
an operator says otherwise — see retention
for why that is the default and why the in-memory store does the
opposite — so this is the hook for whatever already schedules work: a
cron entry, a Kubernetes CronJob, a tokio interval in your own
binary.
Only Completed, Failed, Canceled and Rejected tasks are
eligible. A task still Working, or parked in InputRequired waiting
on a human, is never deleted however old it is.
Safe to run from several replicas at once: each batch is a single
DELETE whose subquery locks the rows it picks with FOR UPDATE SKIP LOCKED, so a sweep never waits for a row another sweep holds and never
deletes one twice. A sweep that finds only rows another sweep has
locked deletes nothing and reports complete, because the sweep that
holds them is deleting them.
§Errors
Returns an error if a delete fails. A sweep that fails partway has still committed its earlier batches; the counts in the returned report are lost in that case, but the deletions are not undone and the next sweep simply continues.
Source§impl TenantAwarePostgresTaskStore
impl TenantAwarePostgresTaskStore
Sourcepub async fn migrate_caller_keys(
&self,
map: impl Fn(&str) -> Option<String>,
) -> Result<CallerKeyMigration, Error>
Available on crate feature postgres only.
pub async fn migrate_caller_keys( &self, map: impl Fn(&str) -> Option<String>, ) -> Result<CallerKeyMigration, Error>
postgres only.Moves each caller partition map renames to its new key, with its
tasks, their logged events and its idempotency keys, in one
transaction (audit register R12); see
caller_keys.
§Errors
A database error, including a task id the new partition already holds; nothing is moved then.
Source§impl TenantAwarePostgresTaskStore
impl TenantAwarePostgresTaskStore
Sourcepub async fn erase_caller(&self, caller: &str) -> Result<CallerErasure, Error>
Available on crate feature postgres only.
pub async fn erase_caller(&self, caller: &str) -> Result<CallerErasure, Error>
postgres only.Removes every partition of caller, in every tenant, with its tasks,
their logged events and its idempotency keys, in one transaction; see
CallerErasure.
§Errors
A database error; nothing is removed then.
Trait Implementations§
Source§impl Clone for TenantAwarePostgresTaskStore
impl Clone for TenantAwarePostgresTaskStore
Source§fn clone(&self) -> TenantAwarePostgresTaskStore
fn clone(&self) -> TenantAwarePostgresTaskStore
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for TenantAwarePostgresTaskStore
impl Debug for TenantAwarePostgresTaskStore
Source§impl TaskStore for TenantAwarePostgresTaskStore
impl TaskStore for TenantAwarePostgresTaskStore
Source§fn isolates_tenants(&self) -> bool
fn isolates_tenants(&self) -> bool
Source§fn supports_idempotency(&self) -> bool
fn supports_idempotency(&self) -> bool
Source§fn database(&self) -> Option<StoreDatabase>
fn database(&self) -> Option<StoreDatabase>
CLIENT span around each of the store’s operations and measures in
db.client.operation.duration (the OpenTelemetry database
conventions; crate::store::traced). Read moreSource§fn turn_claims(&self) -> Option<Arc<dyn TurnClaimStore>>
fn turn_claims(&self) -> Option<Arc<dyn TurnClaimStore>>
crate::store::claim). Read moreSource§fn claim_idempotency_key<'a>(
&'a self,
key: &'a str,
message_id: &'a MessageId,
task_id: &'a TaskId,
) -> Pin<Box<dyn Future<Output = Result<IdempotencyClaim, A2aError>> + Send + 'a>>
fn claim_idempotency_key<'a>( &'a self, key: &'a str, message_id: &'a MessageId, task_id: &'a TaskId, ) -> Pin<Box<dyn Future<Output = Result<IdempotencyClaim, A2aError>> + Send + 'a>>
Source§fn release_idempotency_key<'a>(
&'a self,
key: &'a str,
) -> Pin<Box<dyn Future<Output = Result<(), A2aError>> + Send + 'a>>
fn release_idempotency_key<'a>( &'a self, key: &'a str, ) -> Pin<Box<dyn Future<Output = Result<(), A2aError>> + Send + 'a>>
claim_idempotency_key,
so it can be claimed again. Read moreSource§fn idempotency_holder<'a>(
&'a self,
key: &'a str,
) -> Pin<Box<dyn Future<Output = Result<Option<IdempotencyHolder>, A2aError>> + Send + 'a>>
fn idempotency_holder<'a>( &'a self, key: &'a str, ) -> Pin<Box<dyn Future<Output = Result<Option<IdempotencyHolder>, A2aError>> + Send + 'a>>
Source§fn save<'a>(
&'a self,
task: &'a Task,
) -> Pin<Box<dyn Future<Output = Result<(), A2aError>> + Send + 'a>>
fn save<'a>( &'a self, task: &'a Task, ) -> Pin<Box<dyn Future<Output = Result<(), A2aError>> + Send + 'a>>
Source§fn get<'a>(
&'a self,
id: &'a TaskId,
) -> Pin<Box<dyn Future<Output = Result<Option<Task>, A2aError>> + Send + 'a>>
fn get<'a>( &'a self, id: &'a TaskId, ) -> Pin<Box<dyn Future<Output = Result<Option<Task>, A2aError>> + Send + 'a>>
None if not found. Read moreSource§fn get_with_position<'a>(
&'a self,
id: &'a TaskId,
) -> Pin<Box<dyn Future<Output = Result<Option<(Task, Option<u64>)>, A2aError>> + Send + 'a>>
fn get_with_position<'a>( &'a self, id: &'a TaskId, ) -> Pin<Box<dyn Future<Output = Result<Option<(Task, Option<u64>)>, A2aError>> + Send + 'a>>
Source§fn list<'a>(
&'a self,
params: &'a ListTasksParams,
) -> Pin<Box<dyn Future<Output = Result<TaskListResponse, A2aError>> + Send + 'a>>
fn list<'a>( &'a self, params: &'a ListTasksParams, ) -> Pin<Box<dyn Future<Output = Result<TaskListResponse, A2aError>> + Send + 'a>>
Source§fn insert_if_absent<'a>(
&'a self,
task: &'a Task,
) -> Pin<Box<dyn Future<Output = Result<bool, A2aError>> + Send + 'a>>
fn insert_if_absent<'a>( &'a self, task: &'a Task, ) -> Pin<Box<dyn Future<Output = Result<bool, A2aError>> + Send + 'a>>
Source§fn delete<'a>(
&'a self,
id: &'a TaskId,
) -> Pin<Box<dyn Future<Output = Result<(), A2aError>> + Send + 'a>>
fn delete<'a>( &'a self, id: &'a TaskId, ) -> Pin<Box<dyn Future<Output = Result<(), A2aError>> + Send + 'a>>
Source§fn supports_event_log(&self) -> bool
fn supports_event_log(&self) -> bool
Source§fn append_event<'a>(
&'a self,
task_id: &'a TaskId,
seq: u64,
event: &'a StreamResponse,
) -> Pin<Box<dyn Future<Output = Result<(), A2aError>> + Send + 'a>>
fn append_event<'a>( &'a self, task_id: &'a TaskId, seq: u64, event: &'a StreamResponse, ) -> Pin<Box<dyn Future<Output = Result<(), A2aError>> + Send + 'a>>
seq in the task’s log. Read moreSource§fn watch_event_log(
&self,
task_id: &TaskId,
) -> Option<Pin<Box<dyn Future<Output = LogWake> + Send>>>
fn watch_event_log( &self, task_id: &TaskId, ) -> Option<Pin<Box<dyn Future<Output = LogWake> + Send>>>
SubscribeToTask stream that would otherwise read the store on a timer
(audit E-F25 (b), ADR 0057). None, the default, is a store that
cannot say. Read moreSource§fn last_event_seq<'a>(
&'a self,
task_id: &'a TaskId,
) -> Pin<Box<dyn Future<Output = Result<u64, A2aError>> + Send + 'a>>
fn last_event_seq<'a>( &'a self, task_id: &'a TaskId, ) -> Pin<Box<dyn Future<Output = Result<u64, A2aError>> + Send + 'a>>
seq this task’s log holds, or 0 when it is empty. Read moreSource§fn earliest_event_seq<'a>(
&'a self,
task_id: &'a TaskId,
) -> Pin<Box<dyn Future<Output = Result<Option<u64>, A2aError>> + Send + 'a>>
fn earliest_event_seq<'a>( &'a self, task_id: &'a TaskId, ) -> Pin<Box<dyn Future<Output = Result<Option<u64>, A2aError>> + Send + 'a>>
seq this task’s log still holds, or None when it holds
nothing — or when the store cannot say, which is the default. Read moreSource§fn trim_event_log<'a>(
&'a self,
task_id: &'a TaskId,
below: u64,
) -> Pin<Box<dyn Future<Output = Result<u64, A2aError>> + Send + 'a>>
fn trim_event_log<'a>( &'a self, task_id: &'a TaskId, below: u64, ) -> Pin<Box<dyn Future<Output = Result<u64, A2aError>> + Send + 'a>>
below, and returns how
many it dropped: the compaction of a live task’s log (audit H13, ADR
0047, option C), which
RetentionPolicy::max_events_per_live_task
drives from the SQL stores’ purge_expired. Read moreSource§fn read_events<'a>(
&'a self,
task_id: &'a TaskId,
after_seq: u64,
limit: usize,
) -> Pin<Box<dyn Future<Output = Result<Vec<RecordedEvent>, A2aError>> + Send + 'a>>
fn read_events<'a>( &'a self, task_id: &'a TaskId, after_seq: u64, limit: usize, ) -> Pin<Box<dyn Future<Output = Result<Vec<RecordedEvent>, A2aError>> + Send + 'a>>
after_seq. Read moreSource§fn count<'a>(
&'a self,
) -> Pin<Box<dyn Future<Output = Result<u64, A2aError>> + Send + 'a>>
fn count<'a>( &'a self, ) -> Pin<Box<dyn Future<Output = Result<u64, A2aError>> + Send + 'a>>
Source§fn health<'a>(
&'a self,
) -> Pin<Box<dyn Future<Output = Result<(), A2aError>> + Send + 'a>>
fn health<'a>( &'a self, ) -> Pin<Box<dyn Future<Output = Result<(), A2aError>> + Send + 'a>>
RequestHandler::task_store_health). Read moreSource§fn is_process_local(&self) -> bool
fn is_process_local(&self) -> bool
Source§fn seals_content(&self) -> bool
fn seals_content(&self) -> bool
Source§fn save_artifact_delta<'a>(
&'a self,
task: &'a Task,
delta: ArtifactDelta,
) -> Pin<Box<dyn Future<Output = Result<(), A2aError>> + Send + 'a>>
fn save_artifact_delta<'a>( &'a self, task: &'a Task, delta: ArtifactDelta, ) -> Pin<Box<dyn Future<Output = Result<(), A2aError>> + Send + 'a>>
task. Read moreSource§fn save_status_delta<'a>(
&'a self,
task: &'a Task,
) -> Pin<Box<dyn Future<Output = Result<(), A2aError>> + Send + 'a>>
fn save_status_delta<'a>( &'a self, task: &'a Task, ) -> Pin<Box<dyn Future<Output = Result<(), A2aError>> + Send + 'a>>
Source§fn try_save_artifact_delta<'a>(
&'a self,
_task: &'a Task,
_delta: ArtifactDelta,
) -> Pin<Box<dyn Future<Output = Result<bool, A2aError>> + Send + 'a>>
fn try_save_artifact_delta<'a>( &'a self, _task: &'a Task, _delta: ArtifactDelta, ) -> Pin<Box<dyn Future<Output = Result<bool, A2aError>> + Send + 'a>>
Ok(true) when applied, Ok(false) when the
caller must write the task whole. Read moreSource§fn try_save_status_delta<'a>(
&'a self,
_task: &'a Task,
) -> Pin<Box<dyn Future<Output = Result<bool, A2aError>> + Send + 'a>>
fn try_save_status_delta<'a>( &'a self, _task: &'a Task, ) -> Pin<Box<dyn Future<Output = Result<bool, A2aError>> + Send + 'a>>
try_save_artifact_delta for
save_status_delta: writes the status
in place and returns true, or writes nothing and returns false. Read moreSource§fn save_appending_history<'a>(
&'a self,
task: &'a Task,
messages: &'a [Message],
limit: HistoryLimit,
) -> Pin<Box<dyn Future<Output = Result<(), A2aError>> + Send + 'a>>
fn save_appending_history<'a>( &'a self, task: &'a Task, messages: &'a [Message], limit: HistoryLimit, ) -> Pin<Box<dyn Future<Output = Result<(), A2aError>> + Send + 'a>>
messages, without the caller
shipping the history it has already stored. Read moreSource§fn hold_events(&self, task_id: &TaskId, after: u64) -> Option<EventHold>
fn hold_events(&self, task_id: &TaskId, after: u64) -> Option<EventHold>
after for a stream that still owes those
positions, until the hold is advanced or dropped (spec §3.5.2); see
EventHolds. Synchronous: a stream takes
it while it is built. A wrapper must forward it. Read moreAuto Trait Implementations§
impl !RefUnwindSafe for TenantAwarePostgresTaskStore
impl !UnwindSafe for TenantAwarePostgresTaskStore
impl Forget for TenantAwarePostgresTaskStore
impl Freeze for TenantAwarePostgresTaskStore
impl Move for TenantAwarePostgresTaskStore
impl Send for TenantAwarePostgresTaskStore
impl Sync for TenantAwarePostgresTaskStore
impl Unpin for TenantAwarePostgresTaskStore
impl UnsafeUnpin for TenantAwarePostgresTaskStore
Blanket Implementations§
§impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
§impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§impl<T> FutureExt for T
impl<T> FutureExt for T
§fn with_context(self, otel_cx: Context) -> WithContext<Self> ⓘ
fn with_context(self, otel_cx: Context) -> WithContext<Self> ⓘ
§fn with_current_context(self) -> WithContext<Self> ⓘ
fn with_current_context(self) -> WithContext<Self> ⓘ
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more§impl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
T in a tonic::Request§impl<L> LayerExt<L> for L
impl<L> LayerExt<L> for L
§fn named_layer<S>(&self, service: S) -> Layered<<L as Layer<S>>::Service, S>where
L: Layer<S>,
fn named_layer<S>(&self, service: S) -> Layered<<L as Layer<S>>::Service, S>where
L: Layer<S>,
Layered].