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.
This commit is contained in:
@@ -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())
|
||||
|
||||
|
||||
Reference in New Issue
Block a user