2018-01-03 07:04:48 +01:00
|
|
|
// Copyright 2018 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 daemon
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"os"
|
|
|
|
"os/signal"
|
2018-01-03 07:40:26 +01:00
|
|
|
"syscall"
|
2018-01-03 07:04:48 +01:00
|
|
|
"time"
|
|
|
|
|
|
|
|
"github.com/miniflux/miniflux/config"
|
|
|
|
"github.com/miniflux/miniflux/logger"
|
|
|
|
"github.com/miniflux/miniflux/reader/feed"
|
|
|
|
"github.com/miniflux/miniflux/scheduler"
|
|
|
|
"github.com/miniflux/miniflux/storage"
|
|
|
|
)
|
|
|
|
|
|
|
|
// Run starts the daemon.
|
|
|
|
func Run(cfg *config.Config, store *storage.Storage) {
|
|
|
|
logger.Info("Starting Miniflux...")
|
|
|
|
|
|
|
|
stop := make(chan os.Signal, 1)
|
|
|
|
signal.Notify(stop, os.Interrupt)
|
2018-01-03 07:40:26 +01:00
|
|
|
signal.Notify(stop, syscall.SIGTERM)
|
2018-01-03 07:04:48 +01:00
|
|
|
|
|
|
|
feedHandler := feed.NewFeedHandler(store)
|
2018-01-16 03:08:30 +01:00
|
|
|
pool := scheduler.NewWorkerPool(feedHandler, cfg.WorkerPoolSize())
|
2018-01-03 07:04:48 +01:00
|
|
|
server := newServer(cfg, store, pool, feedHandler)
|
|
|
|
|
|
|
|
scheduler.NewFeedScheduler(
|
|
|
|
store,
|
|
|
|
pool,
|
2018-01-16 03:08:30 +01:00
|
|
|
cfg.PollingFrequency(),
|
|
|
|
cfg.BatchSize(),
|
2018-01-03 07:04:48 +01:00
|
|
|
)
|
|
|
|
|
2018-01-16 03:08:30 +01:00
|
|
|
scheduler.NewSessionScheduler(store, cfg.SessionCleanupFrequency())
|
2018-01-03 07:04:48 +01:00
|
|
|
|
|
|
|
<-stop
|
|
|
|
logger.Info("Shutting down the server...")
|
|
|
|
ctx, _ := context.WithTimeout(context.Background(), 5*time.Second)
|
|
|
|
server.Shutdown(ctx)
|
|
|
|
store.Close()
|
|
|
|
logger.Info("Server gracefully stopped")
|
|
|
|
}
|