4
0

daemon.go 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  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. package daemon
  5. import (
  6. "context"
  7. "os"
  8. "os/signal"
  9. "syscall"
  10. "time"
  11. "github.com/miniflux/miniflux/config"
  12. "github.com/miniflux/miniflux/logger"
  13. "github.com/miniflux/miniflux/reader/feed"
  14. "github.com/miniflux/miniflux/scheduler"
  15. "github.com/miniflux/miniflux/storage"
  16. )
  17. // Run starts the daemon.
  18. func Run(cfg *config.Config, store *storage.Storage) {
  19. logger.Info("Starting Miniflux...")
  20. stop := make(chan os.Signal, 1)
  21. signal.Notify(stop, os.Interrupt)
  22. signal.Notify(stop, syscall.SIGTERM)
  23. feedHandler := feed.NewFeedHandler(store)
  24. pool := scheduler.NewWorkerPool(feedHandler, cfg.GetInt("WORKER_POOL_SIZE", config.DefaultWorkerPoolSize))
  25. server := newServer(cfg, store, pool, feedHandler)
  26. scheduler.NewFeedScheduler(
  27. store,
  28. pool,
  29. cfg.GetInt("POLLING_FREQUENCY", config.DefaultPollingFrequency),
  30. cfg.GetInt("BATCH_SIZE", config.DefaultBatchSize),
  31. )
  32. scheduler.NewSessionScheduler(store, config.DefaultSessionCleanupFrequency)
  33. <-stop
  34. logger.Info("Shutting down the server...")
  35. ctx, _ := context.WithTimeout(context.Background(), 5*time.Second)
  36. server.Shutdown(ctx)
  37. store.Close()
  38. logger.Info("Server gracefully stopped")
  39. }