From 71c415e958176bf9b867f907771188c059e92782 Mon Sep 17 00:00:00 2001 From: John O'Keefe Date: Thu, 5 Mar 2026 20:26:33 -0500 Subject: [PATCH] feat: enhance Worker service with job tracking capabilities - Add Priority field to Job struct for future job prioritization - Add HasActiveScans() method to check if any scans are currently running - Add GetActiveJobCount() method to count running and pending jobs - Remove unused JobTypeSync constant These changes enable more accurate health check reporting and prepare for future job priority queue implementation. --- internal/services/worker.go | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/internal/services/worker.go b/internal/services/worker.go index 5f0e09e..27318af 100644 --- a/internal/services/worker.go +++ b/internal/services/worker.go @@ -38,7 +38,6 @@ const ( JobTypeThumbnails JobType = "thumbnails" JobTypeBackup JobType = "backup" JobTypeAnalytics JobType = "analytics" - JobTypeSync JobType = "sync" ) var WorkerInstance *Worker @@ -55,6 +54,7 @@ type Job struct { ID string Type JobType UserID string + Priority int Params map[string]interface{} Status JobStatus CreatedAt time.Time @@ -94,6 +94,29 @@ type Worker struct { shuttingDown atomic.Bool } +func (w *Worker) HasActiveScans() bool { + w.mu.RLock() + defer w.mu.RUnlock() + + for _, result := range w.results { + if result.Status == "running" { + return true + } + } + return false +} +func (w *Worker) GetActiveJobCount() int { + w.mu.RLock() + defer w.mu.RUnlock() + + count := 0 + for _, result := range w.results { + if result.Status == "running" || result.Status == "pending" { + count++ + } + } + return count +} func NewWorker(numWorkers int, connManager *wsync.ConnectionManager) *Worker { ctx, cancel := context.WithCancel(context.Background())