scheduler.go 774 B

12345678910111213141516171819202122232425262728
  1. // Copyright 2017 Frédéric Guillot. All rights reserved.
  2. // Use of this source code is governed by the Apache 2.0
  3. // license that can be found in the LICENSE file.
  4. package scheduler
  5. import (
  6. "time"
  7. "github.com/miniflux/miniflux/logger"
  8. "github.com/miniflux/miniflux/storage"
  9. )
  10. // NewScheduler starts a new scheduler that push jobs to a pool of workers.
  11. func NewScheduler(store *storage.Storage, workerPool *WorkerPool, frequency, batchSize int) {
  12. go func() {
  13. c := time.Tick(time.Duration(frequency) * time.Minute)
  14. for now := range c {
  15. jobs, err := store.NewBatch(batchSize)
  16. if err != nil {
  17. logger.Error("[Scheduler] %v", err)
  18. } else {
  19. logger.Debug("[Scheduler:%v] => Pushing %d jobs", now, len(jobs))
  20. workerPool.Push(jobs)
  21. }
  22. }
  23. }()
  24. }