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"
|
JobTypeThumbnails JobType = "thumbnails"
|
||||||
JobTypeBackup JobType = "backup"
|
JobTypeBackup JobType = "backup"
|
||||||
JobTypeAnalytics JobType = "analytics"
|
JobTypeAnalytics JobType = "analytics"
|
||||||
JobTypeSync JobType = "sync"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
var WorkerInstance *Worker
|
var WorkerInstance *Worker
|
||||||
@@ -55,6 +54,7 @@ type Job struct {
|
|||||||
ID string
|
ID string
|
||||||
Type JobType
|
Type JobType
|
||||||
UserID string
|
UserID string
|
||||||
|
Priority int
|
||||||
Params map[string]interface{}
|
Params map[string]interface{}
|
||||||
Status JobStatus
|
Status JobStatus
|
||||||
CreatedAt time.Time
|
CreatedAt time.Time
|
||||||
@@ -94,6 +94,29 @@ type Worker struct {
|
|||||||
shuttingDown atomic.Bool
|
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 {
|
func NewWorker(numWorkers int, connManager *wsync.ConnectionManager) *Worker {
|
||||||
ctx, cancel := context.WithCancel(context.Background())
|
ctx, cancel := context.WithCancel(context.Background())
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user