Slice 5 of the worker state consolidation refactor.
OverrideSlotService (new in Worker/Queue/) owns RunNow, ContinueTask,
and the override-slot piece of CancelTask. QueueService keeps the
queue-slot guard for "task is already running" rejection and delegates
to OverrideSlotService for execution; CancelTask tries the override
slot first, then the queue slot. QueueSlotState is extracted to its own
file.
Folder reorg (via git mv to preserve history):
- Worker/Queue/ QueueService, OverrideSlotService, QueueSlotState
(alongside existing waker/picker)
- Worker/Lifecycle/ StaleTaskRecovery, TaskResetService, TaskMergeService
- Worker/Worktrees/ WorktreeMaintenanceService
- Worker/Agents/ AgentFileService, DefaultAgentSeeder
Worker/Services/ folder removed. All consumers updated to the new
namespaces (Program.cs, WorkerHub, ExternalMcpService,
PlanningMergeOrchestrator, all Worker tests).
OverrideSlotService is registered as a DI singleton in both the main
worker app and the external MCP app.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
27 lines
877 B
C#
27 lines
877 B
C#
using ClaudeDo.Worker.State;
|
|
|
|
namespace ClaudeDo.Worker.Lifecycle;
|
|
|
|
public sealed class StaleTaskRecovery : IHostedService
|
|
{
|
|
private readonly ITaskStateService _state;
|
|
private readonly ILogger<StaleTaskRecovery> _logger;
|
|
|
|
public StaleTaskRecovery(ITaskStateService state, ILogger<StaleTaskRecovery> logger)
|
|
{
|
|
_state = state;
|
|
_logger = logger;
|
|
}
|
|
|
|
public async Task StartAsync(CancellationToken cancellationToken)
|
|
{
|
|
var flipped = await _state.RecoverStaleRunningAsync("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;
|
|
}
|