diff --git a/internal/services/worker.go b/internal/services/worker.go index 8f509d2..59b7b47 100644 --- a/internal/services/worker.go +++ b/internal/services/worker.go @@ -176,10 +176,17 @@ func (w *Worker) GetActiveJobCount() int { return count } func NewWorker(numWorkers int, connManager *wsync.ConnectionManager) *Worker { + return NewWorkerWithConfig(numWorkers, 100, connManager) +} + +// NewWorkerWithConfig constructs a worker pool with the given worker count and +// job-queue capacity. Used at startup to source values from the settings +// registry. +func NewWorkerWithConfig(numWorkers, queueCap int, connManager *wsync.ConnectionManager) *Worker { ctx, cancel := context.WithCancel(context.Background()) w := &Worker{ - jobQueue: make(chan *Job, 100), + jobQueue: make(chan *Job, queueCap), results: make(map[string]*JobResult), ctx: ctx, cancel: cancel, @@ -995,3 +1002,4 @@ func (w *Worker) Shutdown() { close(w.jobQueue) w.wg.Wait() } + diff --git a/internal/sync/queue.go b/internal/sync/queue.go index b7822e0..4a579b3 100644 --- a/internal/sync/queue.go +++ b/internal/sync/queue.go @@ -74,11 +74,18 @@ type SyncQueueItem struct { } func NewSyncQueueProcessor(db *database.Queries) *SyncQueueProcessor { + return NewSyncQueueProcessorWithConfig(db, 5*time.Second, 50) +} + +// NewSyncQueueProcessorWithConfig constructs a processor with the given flush +// interval and batch size. Used at startup to source values from the settings +// registry. +func NewSyncQueueProcessorWithConfig(db *database.Queries, interval time.Duration, batchSize int) *SyncQueueProcessor { return &SyncQueueProcessor{ db: db, progressChan: make(chan *ProgressUpdate, 100), - interval: 5 * time.Second, - batchSize: 50, + interval: interval, + batchSize: batchSize, } }