# IJobScheduleStore

> 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.ijobschedulestore/
> Summary: IJobScheduleStore: The store for schedule definitions.

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

The store for schedule definitions.

```csharp
public interface IJobScheduleStore
```

## Remarks

Separate from [IJobStore](/api/tracon.ijobstore/): this store holds only the
*definitions* (when, what runs); the actual queued jobs are in
[IJobStore](/api/tracon.ijobstore/). The split is the same as between
[IWorkflowDefinitionStore](/api/tracon.iworkflowdefinitionstore/) and [IWorkflowCheckpointStore](/api/tracon.iworkflowcheckpointstore/).

## Methods

### <a id="Tracon_IJobScheduleStore_DeleteAsync_System_String_System_String_System_Threading_CancellationToken_"></a> DeleteAsync\(string, string, CancellationToken\)

Deletes the schedule.

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

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

`name` [string](https://learn.microsoft.com/dotnet/api/system.string)

The schedule 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_IJobScheduleStore_GetAsync_System_String_System_String_System_Threading_CancellationToken_"></a> GetAsync\(string, string, CancellationToken\)

Fetches the schedule with the given name.

```csharp
ValueTask<JobSchedule?> GetAsync(string tenantId, string name, CancellationToken cancellationToken = default)
```

#### Parameters

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

`name` [string](https://learn.microsoft.com/dotnet/api/system.string)

The schedule 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)<[JobSchedule](/api/tracon.jobschedule/)?\>

The schedule; [null](https://learn.microsoft.com/dotnet/csharp/language-reference/keywords/null) if it does not exist.

### <a id="Tracon_IJobScheduleStore_ListAsync_System_String_System_Threading_CancellationToken_"></a> ListAsync\(string, CancellationToken\)

Lists all of a tenant's schedules, by name.

```csharp
ValueTask<IReadOnlyList<JobSchedule>> ListAsync(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)<[JobSchedule](/api/tracon.jobschedule/)\>\>

The schedules.

### <a id="Tracon_IJobScheduleStore_ListDueAsync_System_DateTimeOffset_System_Threading_CancellationToken_"></a> ListDueAsync\(DateTimeOffset, CancellationToken\)

Lists the schedules of every tenant that are due to run
(`NextRunAt <= asOfUtc`), enabled, and carry a cron expression.

```csharp
ValueTask<IReadOnlyList<JobSchedule>> ListDueAsync(DateTimeOffset asOfUtc, CancellationToken cancellationToken = default)
```

#### Parameters

`asOfUtc` [DateTimeOffset](https://learn.microsoft.com/dotnet/api/system.datetimeoffset)

The comparison moment (UTC).

`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)<[JobSchedule](/api/tracon.jobschedule/)\>\>

The due schedules.

### <a id="Tracon_IJobScheduleStore_SaveAsync_Tracon_JobSchedule_System_Threading_CancellationToken_"></a> SaveAsync\(JobSchedule, CancellationToken\)

Creates or updates the schedule (name + tenant is unique).

```csharp
ValueTask<JobSchedule> SaveAsync(JobSchedule schedule, CancellationToken cancellationToken = default)
```

#### Parameters

`schedule` [JobSchedule](/api/tracon.jobschedule/)

The schedule to save.

`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)<[JobSchedule](/api/tracon.jobschedule/)\>

The saved schedule.

### <a id="Tracon_IJobScheduleStore_TryClaimNextRunAsync_System_Guid_System_DateTimeOffset_System_DateTimeOffset_System_DateTimeOffset_System_Threading_CancellationToken_"></a> TryClaimNextRunAsync\(Guid, DateTimeOffset, DateTimeOffset, DateTimeOffset, CancellationToken\)

Tries to atomically advance a schedule's [JobSchedule.NextRunAt](/api/tracon.jobschedule/#Tracon_JobSchedule_NextRunAt)
field (compare-and-swap).

```csharp
ValueTask<bool> TryClaimNextRunAsync(Guid scheduleId, DateTimeOffset expectedNextRunAt, DateTimeOffset newNextRunAt, DateTimeOffset ranAt, CancellationToken cancellationToken = default)
```

#### Parameters

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

`expectedNextRunAt` [DateTimeOffset](https://learn.microsoft.com/dotnet/api/system.datetimeoffset)

The expected current value. If another instance has already advanced
it, the value does not match and the operation fails — this is how two
overlapping scheduling triggers are prevented.

`newNextRunAt` [DateTimeOffset](https://learn.microsoft.com/dotnet/api/system.datetimeoffset)

The new next-run time.

`ranAt` [DateTimeOffset](https://learn.microsoft.com/dotnet/api/system.datetimeoffset)

The time this trigger happened (UTC).

`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 claim succeeded.
