feat(data,worker): add repositories, stale-task recovery, and test foundation
Data: TagRepository, ListRepository, TaskRepository (incl. queue selection via effective agent tag + scheduled_for filter), WorktreeRepository. All CRUD via parameterized SqliteCommand; enums roundtrip as lowercase strings matching the schema CHECK constraints. Worker: StaleTaskRecovery IHostedService flips running -> failed on startup and marks the result column with a [stale] reason. All four repositories registered as singletons. Tests: DbFixture with temp-file SQLite + schema bootstrap, covering TaskRepository (queue pick via list-tag and task-tag, schedule filter, transitions, stale flip), ListRepository CRUD + junctions, and StaleTaskRecovery. 14 tests pass. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
26
src/ClaudeDo.Worker/Services/StaleTaskRecovery.cs
Normal file
26
src/ClaudeDo.Worker/Services/StaleTaskRecovery.cs
Normal file
@@ -0,0 +1,26 @@
|
||||
using ClaudeDo.Data.Repositories;
|
||||
|
||||
namespace ClaudeDo.Worker.Services;
|
||||
|
||||
public sealed class StaleTaskRecovery : IHostedService
|
||||
{
|
||||
private readonly TaskRepository _tasks;
|
||||
private readonly ILogger<StaleTaskRecovery> _logger;
|
||||
|
||||
public StaleTaskRecovery(TaskRepository tasks, ILogger<StaleTaskRecovery> logger)
|
||||
{
|
||||
_tasks = tasks;
|
||||
_logger = logger;
|
||||
}
|
||||
|
||||
public async Task StartAsync(CancellationToken cancellationToken)
|
||||
{
|
||||
var flipped = await _tasks.FlipAllRunningToFailedAsync("worker restart", cancellationToken);
|
||||
if (flipped > 0)
|
||||
_logger.LogWarning("Stale task recovery: flipped {Count} running task(s) to failed", flipped);
|
||||
else
|
||||
_logger.LogInformation("Stale task recovery: no stale tasks found");
|
||||
}
|
||||
|
||||
public Task StopAsync(CancellationToken cancellationToken) => Task.CompletedTask;
|
||||
}
|
||||
Reference in New Issue
Block a user