TaskManager
Assign one active worker and keep ordered replacements ready.
Three hikers volunteer for one duty
Someone must staff the dispatch desk throughout the storm. Claims would make one hiker its permanent owner; here, the next volunteer takes over if the first leaves. Alice, Bob, and Carol volunteer in order.
Each hiker writes a volunteer request for the same named task. The first accepted volunteer works the desk; the other accepted volunteers form its replacement line. As with Claims, the ranger's numbers decide who is first.
Each hiker remembers their own pending request so they do not send it twice. Who works the desk, and who waits where, stays unconfirmed until the ranger numbers the request.
From volunteers to automatic replacement
- Volunteer for a named task. Accepted volunteers join that task's queue in sequence-number order.
- Assign the queue head. The first connected client is active. The remaining clients wait in a known order.
- Promote after departure. A voluntary leave or a disconnect removes that client. If the client was active, the next connected volunteer becomes active.
- Complete the task. Only the active client can submit completion. Completion closes the task and clears its full volunteer queue.
A disconnect is not another volunteer operation. The runtime updates the connected-client roster, and the kernel removes that client from every task queue.
Run the conflict
Queue several volunteers, then compare promotion after departure with completion of the whole task.
Staff the dispatch desk
Build one ordered volunteer line, then watch the next connected hiker take over.
Assignment ruleQueue head owns the task
Assigned
The first connected volunteer.
- No dispatcher assigned.
Waiting
Promotion follows this order.
- No volunteers waiting.
Task
Completion closes the whole line.
- Dispatch desk open.
Alice
Line statusNot volunteering
Bob
Line statusNot volunteering
Carol
Line statusNot volunteering
Run the worked example
Queue all three volunteers, disconnect Alice, then let promoted dispatcher Bob complete the task.
Enable JavaScript to run the line. The expected result remains in the lesson.
Ready: the dispatch desk is unassigned.
Read the result
Alice is assigned first, with Bob and Carol waiting in order. When Alice disconnects, Bob is promoted without a new election. When Bob completes the task, TaskManager clears the whole volunteer line instead of promoting Carol.
Failover moves the duty, not the work
TaskManager coordinates responsibility, not the work itself. When Bob takes over, the application still decides how to resume what Alice left half done. Completing the task also clears the whole line, and every change needs the ranger station.
The next lesson, PactMap, changes a shared plan only when every connected hiker agrees.
Sources and implementation
Sources:
Watershed's task_manager_kernel.
Implementation: The demo calls task_manager_kernel.volunteer, task_manager_kernel.abandon, task_manager_kernel.complete, task_manager_kernel.remove_client, task_manager_kernel.ack_local, task_manager_kernel.apply_remote, and task_manager_kernel.summary_queues
through the Gleam toolkit. The displayed client records and shared
view come from those kernel results.