mirror of
https://github.com/crawlab-team/crawlab.git
synced 2026-01-21 17:21:09 +01:00
refactor(node): reorganize task reconciliation, prioritize worker cache, add periodic cleanup
- Move and document reconciliation constants and add sectioned organization/comments. - Split large monolithic logic into smaller functions: - reconcileDisconnectedTasks / reconcileDisconnectedTask - reconcileAbandonedAssignedTasks - reconcileStalePendingTasks / handleStalePendingTask - getActualTaskStatus / getStatusFromWorkerCache / triggerWorkerStatusSync - queryProcessStatus / requestProcessStatusFromWorker / mapProcessStatusToTaskStatus - findTasksByStatus / markTaskDisconnected / findAvailableNodeForTask - updateTaskStatus / saveTask / shouldMarkTaskAbnormal / markTaskAbnormal - Add periodic background workers: - StartPeriodicReconciliation -> runPeriodicReconciliation to reconcile running/disconnected tasks - runPeriodicAssignedTaskCleanup -> cleanupStuckAssignedTasks to detect and recover stuck assigned tasks - Prioritize worker-side cached status and attempt sync from task runner before querying worker processes. - Introduce a placeholder createWorkerClient for future gRPC worker discovery/invocation. - Replace ad-hoc DB updates with saveTask using retry/backoff and centralize status update logic. - Improve logging and error messages, and tighten conditions for marking tasks abnormal. This refactor clarifies responsibilities, improves reliability of status updates, and prepares the codebase for future worker gRPC integration.
This commit is contained in: