fix(task): prevent RecoverStuckTasks from re-enqueueing in-flight tasks

RecoverStuckTasks scans for tasks with updated_at > 5min ago and
re-enqueues them. This incorrectly matched tasks actively being
processed by the worker (e.g. slow downloads), causing
double-processing.

Add inflight sync.Map to track taskIDs currently inside ProcessTask.
RecoverStuckTasks skips tasks found in inflight. On server restart
inflight is empty (in-memory), so genuinely stuck tasks are still
correctly recovered.

Also: increase taskCh buffer 16→10000, add periodic RecoverStuckTasks
goroutine in TaskPoller (every 5min), and add status guard in
ProcessTask as defense-in-depth against duplicate enqueues.
This commit is contained in:
dailz
2026-04-21 17:19:10 +08:00
parent 8955e513aa
commit 435ab285c1
3 changed files with 103 additions and 7 deletions

View File

@@ -25,6 +25,8 @@ func (m *mockTaskPollable) RefreshStaleTasks(ctx context.Context) error {
return nil
}
func (m *mockTaskPollable) RecoverStuckTasks(ctx context.Context) {}
func (m *mockTaskPollable) getCallCount() int {
m.mu.Lock()
defer m.mu.Unlock()