miniflux-v2/scheduler/scheduler.go

29 lines
774 B
Go
Raw Normal View History

2017-11-20 06:10:04 +01:00
// Copyright 2017 Frédéric Guillot. All rights reserved.
// Use of this source code is governed by the Apache 2.0
// license that can be found in the LICENSE file.
package scheduler
import (
"time"
2017-12-16 03:55:57 +01:00
"github.com/miniflux/miniflux/logger"
2017-12-13 06:48:13 +01:00
"github.com/miniflux/miniflux/storage"
2017-11-20 06:10:04 +01:00
)
// NewScheduler starts a new scheduler that push jobs to a pool of workers.
2017-11-20 06:10:04 +01:00
func NewScheduler(store *storage.Storage, workerPool *WorkerPool, frequency, batchSize int) {
go func() {
c := time.Tick(time.Duration(frequency) * time.Minute)
for now := range c {
jobs, err := store.NewBatch(batchSize)
if err != nil {
2017-12-16 03:55:57 +01:00
logger.Error("[Scheduler] %v", err)
} else {
2017-12-16 03:55:57 +01:00
logger.Debug("[Scheduler:%v] => Pushing %d jobs", now, len(jobs))
workerPool.Push(jobs)
}
2017-11-20 06:10:04 +01:00
}
}()
2017-11-20 06:10:04 +01:00
}