aboutsummaryrefslogtreecommitdiffhomepage
path: root/scheduler/scheduler.go
blob: cc3de6aa4774d3b05c15e2959960e9f67a92355e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
// 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"

	"github.com/miniflux/miniflux/logger"
	"github.com/miniflux/miniflux/storage"
)

// NewFeedScheduler starts a new scheduler that push jobs to a pool of workers.
func NewFeedScheduler(store *storage.Storage, workerPool *WorkerPool, frequency, batchSize int) {
	go func() {
		c := time.Tick(time.Duration(frequency) * time.Minute)
		for _ = range c {
			jobs, err := store.NewBatch(batchSize)
			if err != nil {
				logger.Error("[FeedScheduler] %v", err)
			} else {
				logger.Debug("[FeedScheduler] Pushing %d jobs", len(jobs))
				workerPool.Push(jobs)
			}
		}
	}()
}

// NewSessionScheduler starts a new scheduler that clean old sessions.
func NewSessionScheduler(store *storage.Storage, frequency int) {
	go func() {
		c := time.Tick(time.Duration(frequency) * time.Hour)
		for _ = range c {
			nbSessions := store.CleanOldSessions()
			nbUserSessions := store.CleanOldUserSessions()
			logger.Debug("[SessionScheduler] cleaned %d sessions and %d user sessions", nbSessions, nbUserSessions)
		}
	}()
}