refactor: filter and action flow (#225)

* refactor: fitler and action flow

* fix: save release before filters

* feat: add action client to notifications

* feat: improve filter check logging
This commit is contained in:
Ludvig Lundgren 2022-04-09 21:20:26 +02:00 committed by GitHub
parent f32379ae76
commit a3854ecd59
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
21 changed files with 654 additions and 313 deletions

View file

@ -2,10 +2,6 @@ package release
import (
"context"
"fmt"
"github.com/rs/zerolog/log"
"github.com/autobrr/autobrr/internal/action"
"github.com/autobrr/autobrr/internal/domain"
)
@ -15,19 +11,16 @@ type Service interface {
Stats(ctx context.Context) (*domain.ReleaseStats, error)
Store(ctx context.Context, release *domain.Release) error
StoreReleaseActionStatus(ctx context.Context, actionStatus *domain.ReleaseActionStatus) error
Process(release domain.Release) error
Delete(ctx context.Context) error
}
type service struct {
repo domain.ReleaseRepo
actionSvc action.Service
repo domain.ReleaseRepo
}
func NewService(repo domain.ReleaseRepo, actionService action.Service) Service {
func NewService(repo domain.ReleaseRepo) Service {
return &service{
repo: repo,
actionSvc: actionService,
repo: repo,
}
}
@ -56,25 +49,6 @@ func (s *service) StoreReleaseActionStatus(ctx context.Context, actionStatus *do
return s.repo.StoreReleaseActionStatus(ctx, actionStatus)
}
func (s *service) Process(release domain.Release) error {
log.Trace().Msgf("start to process release: %+v", release)
if release.Filter.Actions == nil {
return fmt.Errorf("no actions for filter: %v", release.Filter.Name)
}
// smart episode?
// run actions (watchFolder, test, exec, qBittorrent, Deluge etc.)
err := s.actionSvc.RunActions(release.Filter.Actions, release)
if err != nil {
log.Error().Stack().Err(err).Msgf("error running actions for filter: %v", release.Filter.Name)
return err
}
return nil
}
func (s *service) Delete(ctx context.Context) error {
return s.repo.Delete(ctx)
}