Skip to content

Commit

Permalink
Fix to preserve previous version's behavior (#89)
Browse files Browse the repository at this point in the history
Signed-off-by: Kotaro Inoue <k.musaino@gmail.com>
  • Loading branch information
musaprg authored Jan 3, 2024
1 parent 4b80ecc commit 8a2b1e9
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions internal/syncer/syncer.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"github.com/musaprg/annict-epgstation-connector/annict"
"github.com/musaprg/annict-epgstation-connector/epgstation"
"golang.org/x/exp/slices"
"golang.org/x/exp/slog"
"golang.org/x/sync/errgroup"
"net/http"
"path/filepath"
Expand Down Expand Up @@ -149,11 +150,7 @@ func (s *syncer) registerRulesToEpgStation(ctx context.Context, works []annictWo
eg.Go(func() error {
ruleIDs, err := s.getRecordingRuleIDsByAnnictWorkID(work.ID)
switch {
case errors.Is(err, pebble.ErrNotFound):
// no recording rule IDs found for the given Annict work ID
// continue to create a new recording rule
break
case err != nil:
case err != nil && !errors.Is(err, pebble.ErrNotFound):
return fmt.Errorf("failed to get recording rule IDs for Annict work ID %s: %w", work.ID, err)
case err == nil:
// recording rule IDs found for the given Annict work ID
Expand All @@ -162,6 +159,13 @@ func (s *syncer) registerRulesToEpgStation(ctx context.Context, works []annictWo
}
return nil
}
if rules, _ := s.getRulesByKeyword(ctx, work.Title); len(rules) != 0 {
// recording rule with same keyword has already been registered
// skip registration
// TODO: Remove this logic after introducing cleanup logic
slog.Info("recording rule with same keyword has already been registered", slog.String("keyword", work.Title))
return nil
}
body := epgstation.PostRulesJSONRequestBody{
SearchOption: epgstation.RuleSearchOption{
GR: epgstation.NewTruePointer(),
Expand Down

0 comments on commit 8a2b1e9

Please sign in to comment.