InMemoryPendingApprovalStore
AgentPrism.Core.dllA store that keeps pending approval requests in process memory.
public sealed class InMemoryPendingApprovalStore : IPendingApprovalStoreInheritance
Section titled “Inheritance”object ← InMemoryPendingApprovalStore
Implements
Section titled “Implements”Inherited Members
Section titled “Inherited Members”object.GetType(), object.ToString(), object.Equals(object?), object.Equals(object?, object?), object.ReferenceEquals(object?, object?), object.GetHashCode()
Remarks
Section titled “Remarks”Limits: process lifetime and a single node. In production, use
AgentPrism.PostgreSql or AgentPrism.SqlServer/AgentPrism.Sqlite.
Constructors
Section titled “Constructors”InMemoryPendingApprovalStore(ITenantContext?)
Section titled “ InMemoryPendingApprovalStore(ITenantContext?)”Initializes a new in-memory approval store.
public InMemoryPendingApprovalStore(ITenantContext? tenantContext = null)Parameters
Section titled “Parameters”tenantContext ITenantContext?
The current tenant context. If this is not supplied, the store behaves as single tenant.
Methods
Section titled “Methods”CreateAsync(PendingApproval, CancellationToken)
Section titled “ CreateAsync(PendingApproval, CancellationToken)”Creates a new pending approval request.
public ValueTask CreateAsync(PendingApproval approval, CancellationToken cancellationToken = default)Parameters
Section titled “Parameters”approval PendingApproval
The request to save. PendingApproval.Status must be ApprovalStatus.Pending.
cancellationToken CancellationToken
The cancellation token.
Returns
Section titled “Returns”DecideAsync(Guid, bool, string, DateTimeOffset, CancellationToken)
Section titled “ DecideAsync(Guid, bool, string, DateTimeOffset, CancellationToken)”Writes a decision on a pending request.
public ValueTask<bool> DecideAsync(Guid id, bool approved, string decidedBy, DateTimeOffset decidedAt, CancellationToken cancellationToken = default)Parameters
Section titled “Parameters”id Guid
The request id.
approved bool
Whether the request is approved.
decidedBy string
The actor that made the decision.
decidedAt DateTimeOffset
The time of the decision.
cancellationToken CancellationToken
The cancellation token.
Returns
Section titled “Returns”true when the decision is written; false when the request is not found in the caller’s tenant or is no longer in the ApprovalStatus.Pending state (a second decision is rejected silently).
ExpireAsync(DateTimeOffset, int, CancellationToken)
Section titled “ ExpireAsync(DateTimeOffset, int, CancellationToken)”Closes the requests that expired before olderThan and are still
in the ApprovalStatus.Pending state, marking them
ApprovalStatus.Expired.
public ValueTask<IReadOnlyList<PendingApproval>> ExpireAsync(DateTimeOffset olderThan, int max, CancellationToken cancellationToken = default)Parameters
Section titled “Parameters”olderThan DateTimeOffset
Requests that expired before this time are closed (UTC).
max int
The upper number of requests closed in this round.
cancellationToken CancellationToken
The cancellation token.
Returns
Section titled “Returns”ValueTask<IReadOnlyList<PendingApproval>>
The records of the closed requests.
Remarks
Section titled “Remarks”[TenantAgnostic]: this is maintenance work and scans the expired requests
of every tenant; filtering by the ambient tenant would leave the requests of the
other tenants ApprovalStatus.Pending forever.
GetAsync(Guid, CancellationToken)
Section titled “ GetAsync(Guid, CancellationToken)”Returns a single pending approval request.
public ValueTask<PendingApproval?> GetAsync(Guid id, CancellationToken cancellationToken = default)Parameters
Section titled “Parameters”id Guid
The request id.
cancellationToken CancellationToken
The cancellation token.
Returns
Section titled “Returns”The request, or null when it is not found in the caller’s tenant.
ListPendingAsync(CancellationToken)
Section titled “ ListPendingAsync(CancellationToken)”Lists the pending requests of the caller’s tenant, ordered from oldest to newest.
public ValueTask<IReadOnlyList<PendingApproval>> ListPendingAsync(CancellationToken cancellationToken = default)Parameters
Section titled “Parameters”cancellationToken CancellationToken
The cancellation token.