Documentation
¶
Overview ¶
Package polling provides the history-polling subsystem for Sonarr/Radarr import events and the write-through poll timestamp cache.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Deps ¶
type Deps struct {
PollCache *PollCache
Store PollerStore
Metrics PollerMetrics
Alerts WarnRecorder
Events PollerEvents
StatsCache StatsCacheInvalidator
}
Deps holds all dependencies for the Poller.
type ImportResult ¶
type ImportResult struct {
Req *subflux.SearchRequest
Source PollSource
Label string
Targets []subflux.SubtitleTarget
RefreshID int
}
ImportResult holds the resolved search parameters for a single arr import event.
type LiveState ¶
type LiveState struct {
Cfg pollerCfg
Engine importSearcher
Sonarr PollSonarrClient
Radarr PollRadarrClient
}
LiveState holds the hot-reloadable runtime state the poller reads each cycle.
type PollCache ¶
type PollCache struct {
// contains filtered or unexported fields
}
PollCache is a write-through cache for poll timestamps. It absorbs transient DB write failures: if the DB write fails, subsequent reads still return the in-memory value instead of re-reading a stale DB entry. On first read after startup, the cache is seeded from the DB via readFn. Uses sync.Map for lock-free reads on the hot path (2 keys, read-heavy).
A failed durable write leaves the cursor DIRTY: memory and disk disagree, and a restart would replay from the older persisted position. That state is explicit — WARN-logged with its onset, retried via RetryDirty on the poll heartbeat, gauged through the optional dirty gauge, and announced when it heals — so restart replay is an expected, explained event instead of a silent drift.
func NewPollCache ¶
func NewPollCache( readFn func(ctx context.Context, key subflux.PollKey) (time.Time, error), setFn func(ctx context.Context, key subflux.PollKey, t time.Time) error, ) *PollCache
NewPollCache creates a PollCache backed by the given read/set functions.
func (*PollCache) Get ¶
Get returns the cached timestamp for key, falling back to the DB on miss. Uses LoadOrStore to handle the race between concurrent first-reads atomically.
func (*PollCache) RetryDirty ¶ added in v0.1.148
RetryDirty re-attempts the durable persist of every dirty cursor using its CURRENT in-memory position. Called on the poll heartbeat so a transient write failure heals within one cycle; a no-op when everything is clean.
func (*PollCache) Set ¶
Set updates both the in-memory cache and the persistent store. The cache advances unconditionally so polling keeps working through disk trouble; a failed durable write marks the cursor dirty (see PollCache doc).
func (*PollCache) SetDirtyGauge ¶ added in v0.1.148
SetDirtyGauge installs an observer for the dirty-cursor count (e.g. a Prometheus gauge). Called with the current count on every transition.
type PollRadarrClient ¶ added in v0.1.106
type PollRadarrClient interface {
HistorySince(ctx context.Context, since time.Time, eventTypes ...arrapi.EventType) ([]arrapi.HistoryRecord, error)
MovieByID(ctx context.Context, id int) (arrapi.Movie, error)
ResolveExcludeTagIDs(ctx context.Context, tagNames []string, logMissing bool) map[int]struct{}
RescanMovie(ctx context.Context, movieID int) error
}
PollRadarrClient is the Radarr surface the history poller uses.
type PollSonarrClient ¶ added in v0.1.106
type PollSonarrClient interface {
HistorySince(ctx context.Context, since time.Time, eventTypes ...arrapi.EventType) ([]arrapi.HistoryRecord, error)
SeriesByID(ctx context.Context, id int) (arrapi.Series, error)
EpisodeByID(ctx context.Context, id int) (arrapi.Episode, error)
ResolveExcludeTagIDs(ctx context.Context, tagNames []string, logMissing bool) map[int]struct{}
RescanSeries(ctx context.Context, seriesID int) error
}
PollSonarrClient is the Sonarr surface the history poller uses: import-event polling, per-item lookups, exclude-tag resolution, and a post-import rescan.
type PollSource ¶
type PollSource string
PollSource identifies the arr system that produced an import event.
const ( PollSourceSonarr PollSource = "sonarr" PollSourceRadarr PollSource = "radarr" )
PollSourceSonarr and PollSourceRadarr are the two supported PollSource values.
type Poller ¶
type Poller struct {
// contains filtered or unexported fields
}
Poller polls Sonarr/Radarr history APIs for new import events and processes each through the search engine.
func NewPoller ¶
NewPoller creates a Poller with the given dependencies. Nothing is captured from the live state here: Run reads the PollInterval per cycle and the exclude-tag read goes to the arr-read wrapper, which owns its own TTL, so a hot-reloaded config takes effect on the next wake.
func (*Poller) PollOnce ¶
PollOnce checks both Sonarr and Radarr for new import events and enqueues what it finds for the executor; it performs NO import processing itself. Returns the number of imported-history entries observed across both arr clients (used by Run to decide whether to enter adaptive-burst mode).
func (*Poller) Run ¶
Run polls on a timer, re-reading the interval from live config after each poll so hot-reloaded interval changes take effect immediately. When PollOnce reports activity, the next interval is shortened to burstPollInterval and stays there until burstPollWindow passes idle.
Detection and execution are decoupled (P12): the timer loop only FETCHES history and enqueues batches, so new imports are observed on schedule even while a large batch is still being worked through; the single-worker executor goroutine drains the queue with the existing pacing and watermark semantics.
type PollerEvents ¶
PollerEvents is the events surface the poller consumes.
type PollerMetrics ¶
PollerMetrics is the metrics surface the poller consumes.
type PollerStore ¶
type PollerStore interface {
DeleteStateByPaths(ctx context.Context, paths []string) (subflux.CleanupResult, error)
}
PollerStore is ONE of the 36 methods the store offers. An import cleans up the rows of a video that disappeared between poll cycles and does nothing else with the store; the poll watermark itself goes through PollCache, which the server builds over the store on the poller's behalf.
type StateFunc ¶
type StateFunc func() *LiveState
StateFunc returns the current live state, called each poll cycle to pick up hot-reloaded config/clients.
type StatsCacheInvalidator ¶
type StatsCacheInvalidator interface {
Invalidate()
}
StatsCacheInvalidator is the narrow interface for stats cache invalidation.
type WarnRecorder ¶ added in v0.4.0
type WarnRecorder interface {
RecordWarn(source, msg string)
}
WarnRecorder records an actionable warning for the UI's alert list. activity.AlertLog satisfies it structurally.