BindCommand associates an injected command ID with a task. This enables reverse lookup from command results to tasks.
(sessionID string, taskID uint32, cmdID string)
| 160 | // BindCommand associates an injected command ID with a task. |
| 161 | // This enables reverse lookup from command results to tasks. |
| 162 | func (tm *TaskManager) BindCommand(sessionID string, taskID uint32, cmdID string) { |
| 163 | key := taskKey{sessionID, taskID} |
| 164 | |
| 165 | tm.mu.Lock() |
| 166 | defer tm.mu.Unlock() |
| 167 | |
| 168 | task, ok := tm.tasks[key] |
| 169 | if !ok { |
| 170 | return |
| 171 | } |
| 172 | |
| 173 | task.mu.Lock() |
| 174 | task.subCmds = append(task.subCmds, cmdID) |
| 175 | if task.State == TaskPending { |
| 176 | task.State = TaskRunning |
| 177 | } |
| 178 | task.UpdatedAt = time.Now() |
| 179 | task.mu.Unlock() |
| 180 | |
| 181 | tm.subIndex[cmdID] = task |
| 182 | } |
| 183 | |
| 184 | // LookupByCommand returns the task associated with a command ID, or nil. |
| 185 | func (tm *TaskManager) LookupByCommand(cmdID string) *Task { |
no outgoing calls