class TaskStore
In-memory task registry with pub/sub for streaming and webhook delivery. Swap for a DB-backed implementation in production -- if the server crashes, in-memory tasks vanish and the client never gets notified.
Definitions
def subscribe(task_id)
Subscribe to task updates. Returns a Queue that will receive events.
Each event is a Hash: type: :status|:artifact, data: Hash
A nil sentinel signals stream end.
Implementation
def subscribe(task_id)
queue = Thread::Queue.new
@mutex.synchronize do
task = @tasks[task_id]
return nil unless task
task.subscribers << queue
end
queue
end