mirror of
https://github.com/idanoo/autobrr
synced 2025-07-22 16:29:12 +00:00

* feat(lists): integrate Omegabrr * feat(lists): add missing lists index * feat(lists): add db repo * feat(lists): add db migrations * feat(lists): labels * feat(lists): url lists and more arrs * fix(lists): db migrations client_id wrong type * fix(lists): db fields * feat(lists): create list form wip * feat(lists): show in list and create * feat(lists): update and delete * feat(lists): trigger via webhook * feat(lists): add webhook handler * fix(arr): encode json to pointer * feat(lists): rename endpoint to lists * feat(lists): fetch tags from arr * feat(lists): process plaintext lists * feat(lists): add background refresh job * run every 6th hour with a random start delay between 1-35 seconds * feat(lists): refresh on save and improve logging * feat(lists): cast arr client to pointer * feat(lists): improve error handling * feat(lists): reset shows field with match release * feat(lists): filter opts all lists * feat(lists): trigger on update if enabled * feat(lists): update option for lists * feat(lists): show connected filters in list * feat(lists): missing listSvc dep * feat(lists): cleanup * feat(lists): typo arr list * feat(lists): radarr include original * feat(lists): rename ExcludeAlternateTitle to IncludeAlternateTitle * fix(lists): arr client type conversion to pointer * fix(actions): only log panic recover if err not nil * feat(lists): show spinner on save * feat(lists): show icon in filters list * feat(lists): change icon color in filters list * feat(lists): delete relations on filter delete
93 lines
2.2 KiB
Go
93 lines
2.2 KiB
Go
// Copyright (c) 2021 - 2024, Ludvig Lundgren and the autobrr contributors.
|
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
|
|
|
package server
|
|
|
|
import (
|
|
"context"
|
|
"sync"
|
|
"time"
|
|
|
|
"github.com/autobrr/autobrr/internal/domain"
|
|
"github.com/autobrr/autobrr/internal/feed"
|
|
"github.com/autobrr/autobrr/internal/indexer"
|
|
"github.com/autobrr/autobrr/internal/irc"
|
|
"github.com/autobrr/autobrr/internal/list"
|
|
"github.com/autobrr/autobrr/internal/logger"
|
|
"github.com/autobrr/autobrr/internal/scheduler"
|
|
"github.com/autobrr/autobrr/internal/update"
|
|
|
|
"github.com/rs/zerolog"
|
|
)
|
|
|
|
type Server struct {
|
|
log zerolog.Logger
|
|
config *domain.Config
|
|
|
|
indexerService indexer.Service
|
|
ircService irc.Service
|
|
feedService feed.Service
|
|
scheduler scheduler.Service
|
|
listService list.Service
|
|
updateService *update.Service
|
|
|
|
stopWG sync.WaitGroup
|
|
lock sync.Mutex
|
|
}
|
|
|
|
func NewServer(log logger.Logger, config *domain.Config, ircSvc irc.Service, indexerSvc indexer.Service, feedSvc feed.Service, listSvc list.Service, scheduler scheduler.Service, updateSvc *update.Service) *Server {
|
|
return &Server{
|
|
log: log.With().Str("module", "server").Logger(),
|
|
config: config,
|
|
indexerService: indexerSvc,
|
|
ircService: ircSvc,
|
|
feedService: feedSvc,
|
|
listService: listSvc,
|
|
scheduler: scheduler,
|
|
updateService: updateSvc,
|
|
}
|
|
}
|
|
|
|
func (s *Server) Start() error {
|
|
go s.checkUpdates()
|
|
|
|
// start cron scheduler
|
|
s.scheduler.Start()
|
|
|
|
// instantiate indexers
|
|
if err := s.indexerService.Start(); err != nil {
|
|
s.log.Error().Err(err).Msg("Could not start indexer service")
|
|
return err
|
|
}
|
|
|
|
// instantiate and start irc networks
|
|
s.ircService.StartHandlers()
|
|
|
|
// start torznab feeds
|
|
if err := s.feedService.Start(); err != nil {
|
|
s.log.Error().Err(err).Msg("Could not start feed service")
|
|
}
|
|
|
|
// start lists background updater
|
|
go s.listService.Start()
|
|
|
|
return nil
|
|
}
|
|
|
|
func (s *Server) Shutdown() {
|
|
s.log.Info().Msg("Shutting down server")
|
|
|
|
// stop all irc handlers
|
|
s.ircService.StopHandlers()
|
|
|
|
// stop cron scheduler
|
|
s.scheduler.Stop()
|
|
}
|
|
|
|
func (s *Server) checkUpdates() {
|
|
if s.config.CheckForUpdates {
|
|
time.Sleep(1 * time.Second)
|
|
|
|
s.updateService.CheckUpdates(context.Background())
|
|
}
|
|
}
|