miniflux/scheduler/scheduler.go
Frédéric Guillot 84d912c979 Rewrite imports
2017-12-12 21:48:13 -08:00

28 lines
738 B
Go

// 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 (
"log"
"time"
"github.com/miniflux/miniflux/storage"
)
// NewScheduler starts a new scheduler that push jobs to a pool of workers.
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 {
log.Println("[Scheduler]", err)
} else {
log.Printf("[Scheduler:%v] => Pushing %d jobs\n", now, len(jobs))
workerPool.Push(jobs)
}
}
}()
}