-
Notifications
You must be signed in to change notification settings - Fork 0
Custom Store
github-actions[bot] edited this page May 14, 2026
·
1 revision
Implement ITaskStateStore to back the manager with anything — a file, a database, an external API.
public interface ITaskStateStore
{
Task<bool> IsRunningAsync(string taskName, CancellationToken ct = default);
Task<bool> IsExpiredAsync(string taskName, CancellationToken ct = default);
Task SetRunningAsync(string taskName, TimeSpan? maxRuntime = null, CancellationToken ct = default);
Task SetStoppedAsync(string taskName, CancellationToken ct = default);
Task CleanupAsync(CancellationToken ct = default);
}| Method | Responsibility |
|---|---|
IsRunningAsync |
Returns true if a record exists for taskName
|
IsExpiredAsync |
Returns true if the record exists but its maxRuntime has elapsed |
SetRunningAsync |
Creates or updates the record, optionally with an expiry |
SetStoppedAsync |
Removes the record |
CleanupAsync |
Removes all records — called on startup when CleanupOnStartup = true
|
// Let DI create the store:
builder.Services.AddTaskTurnstile()
.UseTaskStateStore<MyCustomStore>();
// Or use a factory:
builder.Services.AddTaskTurnstile()
.UseTaskStateStore(sp => new MyCustomStore("/var/run/locks"));See samples/FileStore/FileTaskStateStore.cs for a complete file-based implementation.