address review: nil-guard reloaded tasks and SyncTask to ActiveTopology
- skip nil entries from LoadAllTaskStates (corrupted state) - re-sync restored tasks with MaintenanceIntegration so ActiveTopology (in-memory, empty on startup) knows about them; otherwise GetNextTask's AssignTask rejects them as unknown and they never get assigned
This commit is contained in:
parent
e31f0bff50
commit
6681d9537c
@ -52,9 +52,13 @@ func (mq *MaintenanceQueue) LoadTasksFromPersistence() error {
|
||||
}
|
||||
|
||||
var terminal []string
|
||||
var restored []*MaintenanceTask
|
||||
mq.mutex.Lock()
|
||||
requeued := 0
|
||||
for _, task := range tasks {
|
||||
if task == nil {
|
||||
continue
|
||||
}
|
||||
switch task.Status {
|
||||
case TaskStatusPending, TaskStatusAssigned, TaskStatusInProgress:
|
||||
task.Status = TaskStatusPending
|
||||
@ -62,6 +66,7 @@ func (mq *MaintenanceQueue) LoadTasksFromPersistence() error {
|
||||
task.Progress = 0
|
||||
mq.tasks[task.ID] = task
|
||||
mq.pendingTasks = append(mq.pendingTasks, task)
|
||||
restored = append(restored, snapshotTask(task))
|
||||
requeued++
|
||||
default:
|
||||
terminal = append(terminal, task.ID)
|
||||
@ -75,6 +80,15 @@ func (mq *MaintenanceQueue) LoadTasksFromPersistence() error {
|
||||
})
|
||||
mq.mutex.Unlock()
|
||||
|
||||
// ActiveTopology is in-memory and starts empty, so restored tasks must be
|
||||
// re-synced or GetNextTask's AssignTask would reject them as unknown and
|
||||
// they'd sit pending forever. Done outside the lock, like the retry path.
|
||||
if mq.integration != nil {
|
||||
for _, task := range restored {
|
||||
mq.integration.SyncTask(task)
|
||||
}
|
||||
}
|
||||
|
||||
// Delete stale terminal files outside the lock to avoid blocking on disk I/O.
|
||||
for _, id := range terminal {
|
||||
mq.deleteTaskState(id)
|
||||
|
||||
Loading…
Reference in New Issue
Block a user