feat(lists): integrate Omegabrr (#1885)

* 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
This commit is contained in:
ze0s 2024-12-25 13:23:37 +01:00 committed by GitHub
parent b68ae334ca
commit 221bc35371
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
77 changed files with 5025 additions and 254 deletions

View file

@ -0,0 +1,68 @@
package list
import (
"context"
"math/rand"
"time"
"github.com/robfig/cron/v3"
"github.com/rs/zerolog"
)
type Job interface {
cron.Job
RunE(ctx context.Context) error
}
type RefreshListSvc interface {
RefreshAll(ctx context.Context) error
}
type RefreshListsJob struct {
log zerolog.Logger
listSvc RefreshListSvc
}
func NewRefreshListsJob(log zerolog.Logger, listSvc RefreshListSvc) Job {
return &RefreshListsJob{log: log, listSvc: listSvc}
}
func (job *RefreshListsJob) Run() {
ctx := context.Background()
if err := job.RunE(ctx); err != nil {
job.log.Error().Err(err).Msg("error refreshing lists")
}
}
func (job *RefreshListsJob) RunE(ctx context.Context) error {
if err := job.run(ctx); err != nil {
job.log.Error().Err(err).Msg("error refreshing lists")
return err
}
return nil
}
func (job *RefreshListsJob) run(ctx context.Context) error {
job.log.Debug().Msg("running refresh lists job")
// Seed the random number generator
rand.New(rand.NewSource(time.Now().UnixNano()))
// Generate a random duration between 1 and 35 seconds
delay := time.Duration(rand.Intn(35-1+1)+1) * time.Second // (35-1+1)+1 => range: 1 to 35
job.log.Debug().Msgf("delaying for %v...", delay)
// Sleep for the calculated duration
time.Sleep(delay)
if err := job.listSvc.RefreshAll(ctx); err != nil {
job.log.Error().Err(err).Msg("error refreshing lists")
return err
}
job.log.Debug().Msg("finished refresh lists job")
return nil
}