mirror of
https://github.com/idanoo/autobrr
synced 2025-07-23 08:49:13 +00:00
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:
parent
f32379ae76
commit
a3854ecd59
21 changed files with 654 additions and 313 deletions
|
@ -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)
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue