|
ndmspc
v1.2.0-0.1.rc6
|
Manages task lifecycle: pending → running → done/failed. More...
#include <NTaskStateManager.h>
Public Types | |
| using | TaskId = size_t |
| using | WorkerId = std::string |
| using | TaskPayload = std::vector< int > |
Public Member Functions | |
| void | AddPending (TaskId id, const TaskPayload &payload) |
| Add a new task to the pending queue. More... | |
| bool | AssignToWorker (const WorkerId &worker, TaskId id) |
| Assign a pending task to a worker (transitions to running) More... | |
| bool | ClaimNextPendingForWorker (const WorkerId &worker, TaskId &id, TaskPayload &payload) |
| Atomically pop the next pending task and assign it to a worker. More... | |
| bool | MarkDone (TaskId id) |
| Mark a running task as completed. More... | |
| bool | MarkFailed (TaskId id) |
| Mark a running task as failed (returns to pending for redistribution) More... | |
| bool | RequeueTask (TaskId id) |
| Requeue a task to pending state from running or done state. More... | |
| std::set< TaskId > | GetWorkerTasks (const WorkerId &worker) const |
| Get all tasks currently assigned to a worker. More... | |
| std::pair< TaskId, TaskPayload > | GetNextPending () |
| Get the next pending task for dispatch. More... | |
| bool | HasPending () const |
| Check if there are pending tasks. More... | |
| std::vector< std::pair< TaskId, TaskPayload > > | RecoverWorkerTasks (const WorkerId &worker) |
| Recover all tasks from a failed worker. More... | |
| bool | RemoveTaskFromWorker (const WorkerId &worker, TaskId id) |
| Remove a specific task ID from a worker (e.g., after ACK but worker later fails) More... | |
| WorkerId | GetTaskWorker (TaskId id) const |
| Get the worker currently executing a task. More... | |
| bool | IsDone (TaskId id) const |
| Check if a task has been completed. More... | |
| size_t | PendingCount () const |
| Get number of pending tasks. | |
| size_t | RunningCount () const |
| Get number of running tasks. | |
| size_t | DoneCount () const |
| Get number of completed tasks. | |
| size_t | TotalCount () const |
| Get total tasks tracked (pending + running + done) | |
| void | Clear () |
| Clear all state (for reuse or cleanup) | |
Private Member Functions | |
| bool | TaskExists (TaskId id) const |
| Check if task exists in any state. | |
| void | EnqueuePending (TaskId id, const TaskPayload &payload) |
| Push task into pending queue and pending-id index. | |
Manages task lifecycle: pending → running → done/failed.
Separates task state management from IPC/worker concerns. Tracks which tasks are assigned to which workers and handles redistribution.
Definition at line 22 of file NTaskStateManager.h.
| void Ndmspc::NTaskStateManager::AddPending | ( | TaskId | id, |
| const TaskPayload & | payload | ||
| ) |
Add a new task to the pending queue.
| id | Unique task identifier |
| payload | Task data (typically coordinates) |
Definition at line 6 of file NTaskStateManager.cxx.
References EnqueuePending(), and TaskExists().
| bool Ndmspc::NTaskStateManager::AssignToWorker | ( | const WorkerId & | worker, |
| TaskId | id | ||
| ) |
Assign a pending task to a worker (transitions to running)
| worker | Worker identifier |
| id | Task ID to assign |
Definition at line 15 of file NTaskStateManager.cxx.
| bool Ndmspc::NTaskStateManager::ClaimNextPendingForWorker | ( | const WorkerId & | worker, |
| TaskId & | id, | ||
| TaskPayload & | payload | ||
| ) |
Atomically pop the next pending task and assign it to a worker.
| worker | Worker identifier |
| id | Output task ID |
| payload | Output task payload |
Definition at line 45 of file NTaskStateManager.cxx.
| std::pair< NTaskStateManager::TaskId, NTaskStateManager::TaskPayload > Ndmspc::NTaskStateManager::GetNextPending | ( | ) |
Get the next pending task for dispatch.
Definition at line 164 of file NTaskStateManager.cxx.
| NTaskStateManager::WorkerId Ndmspc::NTaskStateManager::GetTaskWorker | ( | TaskId | id | ) | const |
Get the worker currently executing a task.
| id | Task ID |
Definition at line 225 of file NTaskStateManager.cxx.
| std::set< NTaskStateManager::TaskId > Ndmspc::NTaskStateManager::GetWorkerTasks | ( | const WorkerId & | worker | ) | const |
Get all tasks currently assigned to a worker.
| worker | Worker identifier |
Definition at line 155 of file NTaskStateManager.cxx.
| bool Ndmspc::NTaskStateManager::HasPending | ( | ) | const |
Check if there are pending tasks.
Definition at line 174 of file NTaskStateManager.cxx.
| bool Ndmspc::NTaskStateManager::IsDone | ( | TaskId | id | ) | const |
Check if a task has been completed.
| id | Task ID |
Definition at line 234 of file NTaskStateManager.cxx.
| bool Ndmspc::NTaskStateManager::MarkDone | ( | TaskId | id | ) |
Mark a running task as completed.
| id | Task ID to mark done |
Definition at line 64 of file NTaskStateManager.cxx.
| bool Ndmspc::NTaskStateManager::MarkFailed | ( | TaskId | id | ) |
Mark a running task as failed (returns to pending for redistribution)
| id | Task ID that failed |
Definition at line 89 of file NTaskStateManager.cxx.
References EnqueuePending().
| std::vector< std::pair< NTaskStateManager::TaskId, NTaskStateManager::TaskPayload > > Ndmspc::NTaskStateManager::RecoverWorkerTasks | ( | const WorkerId & | worker | ) |
Recover all tasks from a failed worker.
| worker | Worker identifier |
Definition at line 180 of file NTaskStateManager.cxx.
References EnqueuePending().
| bool Ndmspc::NTaskStateManager::RemoveTaskFromWorker | ( | const WorkerId & | worker, |
| TaskId | id | ||
| ) |
Remove a specific task ID from a worker (e.g., after ACK but worker later fails)
| worker | Worker identifier |
| id | Task ID to remove |
Definition at line 206 of file NTaskStateManager.cxx.
| bool Ndmspc::NTaskStateManager::RequeueTask | ( | TaskId | id | ) |
Requeue a task to pending state from running or done state.
| id | Task ID to requeue |
Definition at line 115 of file NTaskStateManager.cxx.
References EnqueuePending().