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
Media mediaGuard
Presence presenceGuard
}
Deps holds all dependencies for the Poller.
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) 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 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) 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 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.