# IRetentionPolicyStore

> Tracon documentation. Tracon is a .NET package family that adds a control
> plane on Microsoft Agent Framework, published as NuGet packages that run
> inside your own ASP.NET Core application.
>
> Page: https://tracon.dev/api/tracon.iretentionpolicystore/
> Summary: IRetentionPolicyStore: The control-plane store for retention policies and run history.

<div class="api-provenance">Namespace Tracon · Assembly <code>Tracon.Abstractions.dll</code></div>

The control-plane store for retention policies and run history.

```csharp
public interface IRetentionPolicyStore
```

## Remarks

The data plane (actual delete/count/archive-read) goes through
[IRetentionStore](/api/tracon.iretentionstore/). This split matches the
`IJobStore`/`IJobScheduleStore` split in the job queue: the
control plane is always registered (in-memory or SQL), while the data
plane is meaningful only when a SQL provider is enabled.

**DI lifetime — singleton.** Registered as a singleton with
`TryAdd`; a consumer's own registration wins.

## Methods

### <a id="Tracon_IRetentionPolicyStore_AppendRunProgressAsync_System_Guid_System_Int64_System_Int64_System_Threading_CancellationToken_"></a> AppendRunProgressAsync\(Guid, long, long, CancellationToken\)

Increments an in-progress run's counters. Called after each batch.

```csharp
ValueTask AppendRunProgressAsync(Guid runId, long deletedDelta, long archivedDelta, CancellationToken cancellationToken = default)
```

#### Parameters

`runId` [Guid](https://learn.microsoft.com/dotnet/api/system.guid)

The run identifier.

`deletedDelta` [long](https://learn.microsoft.com/dotnet/api/system.int64)

The number of rows deleted in this batch.

`archivedDelta` [long](https://learn.microsoft.com/dotnet/api/system.int64)

The number of rows archived in this batch.

`cancellationToken` [CancellationToken](https://learn.microsoft.com/dotnet/api/system.threading.cancellationtoken)

The cancellation token.

#### Returns

 [ValueTask](https://learn.microsoft.com/dotnet/api/system.threading.tasks.valuetask)

The completion task.

### <a id="Tracon_IRetentionPolicyStore_CompleteRunAsync_System_Guid_System_DateTimeOffset_System_String_System_Threading_CancellationToken_"></a> CompleteRunAsync\(Guid, DateTimeOffset, string?, CancellationToken\)

Finalizes a run.

```csharp
ValueTask CompleteRunAsync(Guid runId, DateTimeOffset completedAt, string? errorMessage, CancellationToken cancellationToken = default)
```

#### Parameters

`runId` [Guid](https://learn.microsoft.com/dotnet/api/system.guid)

The run identifier.

`completedAt` [DateTimeOffset](https://learn.microsoft.com/dotnet/api/system.datetimeoffset)

The completion time (UTC).

`errorMessage` [string](https://learn.microsoft.com/dotnet/api/system.string)?

The error message; [null](https://learn.microsoft.com/dotnet/csharp/language-reference/keywords/null) if successful.

`cancellationToken` [CancellationToken](https://learn.microsoft.com/dotnet/api/system.threading.cancellationtoken)

The cancellation token.

#### Returns

 [ValueTask](https://learn.microsoft.com/dotnet/api/system.threading.tasks.valuetask)

The completion task.

### <a id="Tracon_IRetentionPolicyStore_CreateRunAsync_Tracon_RetentionRun_System_Threading_CancellationToken_"></a> CreateRunAsync\(RetentionRun, CancellationToken\)

Opens a new cleanup run.

```csharp
ValueTask<RetentionRun> CreateRunAsync(RetentionRun run, CancellationToken cancellationToken = default)
```

#### Parameters

`run` [RetentionRun](/api/tracon.retentionrun/)

The starting record. [RetentionRun.CompletedAt](/api/tracon.retentionrun/#Tracon_RetentionRun_CompletedAt) is ignored.

`cancellationToken` [CancellationToken](https://learn.microsoft.com/dotnet/api/system.threading.cancellationtoken)

The cancellation token.

#### Returns

 [ValueTask](https://learn.microsoft.com/dotnet/api/system.threading.tasks.valuetask\-1)<[RetentionRun](/api/tracon.retentionrun/)\>

The created record.

### <a id="Tracon_IRetentionPolicyStore_DeletePolicyAsync_System_String_System_String_System_Threading_CancellationToken_"></a> DeletePolicyAsync\(string, string, CancellationToken\)

Deletes a policy.

```csharp
ValueTask<bool> DeletePolicyAsync(string tenantId, string target, CancellationToken cancellationToken = default)
```

#### Parameters

`tenantId` [string](https://learn.microsoft.com/dotnet/api/system.string)

The tenant identifier.

`target` [string](https://learn.microsoft.com/dotnet/api/system.string)

The target name.

`cancellationToken` [CancellationToken](https://learn.microsoft.com/dotnet/api/system.threading.cancellationtoken)

The cancellation token.

#### Returns

 [ValueTask](https://learn.microsoft.com/dotnet/api/system.threading.tasks.valuetask\-1)<[bool](https://learn.microsoft.com/dotnet/api/system.boolean)\>

[true](https://learn.microsoft.com/dotnet/csharp/language-reference/builtin-types/bool) if the delete happened.

### <a id="Tracon_IRetentionPolicyStore_GetPolicyAsync_System_String_System_String_System_Threading_CancellationToken_"></a> GetPolicyAsync\(string, string, CancellationToken\)

Looks up a single target's policy within the tenant, falling back to the `"*"` tenant-wide policy.

```csharp
ValueTask<RetentionPolicy?> GetPolicyAsync(string tenantId, string target, CancellationToken cancellationToken = default)
```

#### Parameters

`tenantId` [string](https://learn.microsoft.com/dotnet/api/system.string)

The tenant identifier.

`target` [string](https://learn.microsoft.com/dotnet/api/system.string)

The target name.

`cancellationToken` [CancellationToken](https://learn.microsoft.com/dotnet/api/system.threading.cancellationtoken)

The cancellation token.

#### Returns

 [ValueTask](https://learn.microsoft.com/dotnet/api/system.threading.tasks.valuetask\-1)<[RetentionPolicy](/api/tracon.retentionpolicy/)?\>

The policy; [null](https://learn.microsoft.com/dotnet/csharp/language-reference/keywords/null) if none exists at either level.

### <a id="Tracon_IRetentionPolicyStore_ListPoliciesAsync_System_String_System_Threading_CancellationToken_"></a> ListPoliciesAsync\(string, CancellationToken\)

Lists all of a tenant's policies (and the `"*"` tenant-wide ones).

```csharp
ValueTask<IReadOnlyList<RetentionPolicy>> ListPoliciesAsync(string tenantId, CancellationToken cancellationToken = default)
```

#### Parameters

`tenantId` [string](https://learn.microsoft.com/dotnet/api/system.string)

The tenant identifier.

`cancellationToken` [CancellationToken](https://learn.microsoft.com/dotnet/api/system.threading.cancellationtoken)

The cancellation token.

#### Returns

 [ValueTask](https://learn.microsoft.com/dotnet/api/system.threading.tasks.valuetask\-1)<[IReadOnlyList](https://learn.microsoft.com/dotnet/api/system.collections.generic.ireadonlylist\-1)<[RetentionPolicy](/api/tracon.retentionpolicy/)\>\>

The policies.

### <a id="Tracon_IRetentionPolicyStore_ListRunsAsync_System_String_System_String_System_Int32_System_Int32_System_Threading_CancellationToken_"></a> ListRunsAsync\(string, string?, int, int, CancellationToken\)

Lists a tenant's run history. The newest record is returned first.

```csharp
ValueTask<IReadOnlyList<RetentionRun>> ListRunsAsync(string tenantId, string? target, int skip, int take, CancellationToken cancellationToken = default)
```

#### Parameters

`tenantId` [string](https://learn.microsoft.com/dotnet/api/system.string)

The tenant identifier.

`target` [string](https://learn.microsoft.com/dotnet/api/system.string)?

Fetches only this target's runs; all if [null](https://learn.microsoft.com/dotnet/csharp/language-reference/keywords/null).

`skip` [int](https://learn.microsoft.com/dotnet/api/system.int32)

The number of records to skip.

`take` [int](https://learn.microsoft.com/dotnet/api/system.int32)

The maximum number of records to fetch.

`cancellationToken` [CancellationToken](https://learn.microsoft.com/dotnet/api/system.threading.cancellationtoken)

The cancellation token.

#### Returns

 [ValueTask](https://learn.microsoft.com/dotnet/api/system.threading.tasks.valuetask\-1)<[IReadOnlyList](https://learn.microsoft.com/dotnet/api/system.collections.generic.ireadonlylist\-1)<[RetentionRun](/api/tracon.retentionrun/)\>\>

The records.

### <a id="Tracon_IRetentionPolicyStore_SavePolicyAsync_Tracon_RetentionPolicy_System_Threading_CancellationToken_"></a> SavePolicyAsync\(RetentionPolicy, CancellationToken\)

Creates or updates a policy.

```csharp
ValueTask<RetentionPolicy> SavePolicyAsync(RetentionPolicy policy, CancellationToken cancellationToken = default)
```

#### Parameters

`policy` [RetentionPolicy](/api/tracon.retentionpolicy/)

The policy.

`cancellationToken` [CancellationToken](https://learn.microsoft.com/dotnet/api/system.threading.cancellationtoken)

The cancellation token.

#### Returns

 [ValueTask](https://learn.microsoft.com/dotnet/api/system.threading.tasks.valuetask\-1)<[RetentionPolicy](/api/tracon.retentionpolicy/)\>

The saved policy.
