Table of Contents

Class CapabilityGrantUsePurgeService

Namespace
ReferenceApplication.Web.Governance
Assembly
ReferenceApplication.Web.dll

Purges consumed capability grants from AsiBackbone's EF Core use store once they are past their retention horizon.

public sealed class CapabilityGrantUsePurgeService : BackgroundService, IHostedService, IDisposable
Inheritance
CapabilityGrantUsePurgeService
Implements
Inherited Members

Remarks

AsiBackbone.EntityFrameworkCore.CapabilityGrants.EfCoreCapabilityGrantUseStore keeps each use record until the grant expires plus its retention grace period, so a replay is denied for as long as any validator could accept the grant. It never deletes records on its own: scheduling PurgeExpiredAsync(DateTimeOffset, CancellationToken) is the host's job. This service runs it every UseStorePurgeIntervalSeconds.

The first purge runs one interval after startup, so starting the application never touches a database that has not been migrated yet. Purging only removes records the store would no longer consult, so several replicas may run it concurrently, and a failed cycle is logged and retried at the next interval.

Constructors

CapabilityGrantUsePurgeService(IServiceScopeFactory, IOptions<CapabilityTokenOptions>, TimeProvider, ILogger<CapabilityGrantUsePurgeService>)

Purges consumed capability grants from AsiBackbone's EF Core use store once they are past their retention horizon.

public CapabilityGrantUsePurgeService(IServiceScopeFactory scopeFactory, IOptions<CapabilityTokenOptions> options, TimeProvider timeProvider, ILogger<CapabilityGrantUsePurgeService> logger)

Parameters

scopeFactory IServiceScopeFactory
options IOptions<CapabilityTokenOptions>
timeProvider TimeProvider
logger ILogger<CapabilityGrantUsePurgeService>

Remarks

AsiBackbone.EntityFrameworkCore.CapabilityGrants.EfCoreCapabilityGrantUseStore keeps each use record until the grant expires plus its retention grace period, so a replay is denied for as long as any validator could accept the grant. It never deletes records on its own: scheduling PurgeExpiredAsync(DateTimeOffset, CancellationToken) is the host's job. This service runs it every UseStorePurgeIntervalSeconds.

The first purge runs one interval after startup, so starting the application never touches a database that has not been migrated yet. Purging only removes records the store would no longer consult, so several replicas may run it concurrently, and a failed cycle is logged and retried at the next interval.

Methods

ExecuteAsync(CancellationToken)

This method is called when the IHostedService starts. The implementation should return a task that represents the lifetime of the long running operation(s) being performed.

protected override Task ExecuteAsync(CancellationToken stoppingToken)

Parameters

stoppingToken CancellationToken

Triggered when StopAsync(CancellationToken) is called.

Returns

Task

A Task that represents the long running operations.

Remarks

See Worker Services in .NET for implementation guidelines.

PurgeOnceAsync(CancellationToken)

Purges use records whose retention horizon has passed.

public Task<int> PurgeOnceAsync(CancellationToken cancellationToken = default)

Parameters

cancellationToken CancellationToken

A token that cancels the purge.

Returns

Task<int>

The number of records removed.