1// Copyright 2018 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
5package worker // import "miniflux.app/worker"
6
7import (
8	"miniflux.app/model"
9	"miniflux.app/storage"
10)
11
12// Pool handles a pool of workers.
13type Pool struct {
14	queue chan model.Job
15}
16
17// Push send a list of jobs to the queue.
18func (p *Pool) Push(jobs model.JobList) {
19	for _, job := range jobs {
20		p.queue <- job
21	}
22}
23
24// NewPool creates a pool of background workers.
25func NewPool(store *storage.Storage, nbWorkers int) *Pool {
26	workerPool := &Pool{
27		queue: make(chan model.Job),
28	}
29
30	for i := 0; i < nbWorkers; i++ {
31		worker := &Worker{id: i, store: store}
32		go worker.Run(workerPool.queue)
33	}
34
35	return workerPool
36}
37