scheduler

package
v0.5.21 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 8, 2026 License: AGPL-3.0 Imports: 11 Imported by: 0

Documentation

Overview

Package scheduler provides the periodic full-scan pipeline, DB maintenance, and auth cleanup scheduling for the subflux server.

Index

Constants

View Source
const (
	FullScanAction = "Full Scan"
	FullScanDetail = "Searching library for missing subtitles"
)

FullScanAction and FullScanDetail are the activity strings every full library scan carries (manual and scheduled; the UI keys its last-scan timing row on the action string).

View Source
const AuthCleanupInterval = 15 * time.Minute

AuthCleanupInterval is how often expired sessions and stale auth state are purged from the database.

View Source
const StartupDelay = 30 * time.Second

StartupDelay is the delay before the first scan after startup.

Variables

This section is empty.

Functions

func GuardedScan

func GuardedScan(ctx context.Context, deps *Deps)

GuardedScan acquires the scanning flag before running a full scan.

func PrepareFullScan added in v0.1.148

func PrepareFullScan(deps *Deps, source activity.Source) (actID string, run func(ctx context.Context))

PrepareFullScan starts the full-scan activity entry (with its structured scope and admin-only cancel role), publishes scan:start, and registers the graceful stop callback — the accept sequence, hoisted out of the scan body so the HTTP handler can return the activity id BEFORE the scan runs. The returned run func executes the scan and applies its terminal outcome; the caller owns the ScanningFlag guard and decides whether to run it inline (scheduler tick) or in a background goroutine (HTTP handler).

func Run

func Run(ctx context.Context, deps *Deps)

Run runs the periodic scan and DB maintenance tickers until ctx is cancelled.

func RunDBMaintenance

func RunDBMaintenance(ctx context.Context, deps *Deps)

RunDBMaintenance prunes old state and stale search attempts.

Types

type Deps

type Deps struct {
	DB Store
	// ScanDB is the scan-state surface the full scan needs (recency set,
	// stamps, cycle mark); the composition root passes the same store as DB.
	ScanDB scanning.ScanStore
	// Backoff feeds season-tracker earlyStop seeding; same store again.
	Backoff          scanning.BackoffPrefixReader
	Metrics          scanning.ScanMetrics
	ReconcileMetrics ReconcileMetrics // nil-safe; omit to skip reconcile metrics
	// Events, Activity and Alerts are the scan-engine surfaces; the
	// scheduler uses StartScan/PublishScanStart itself and hands the same
	// three straight to scanning.Deps, so they are scanning's interfaces
	// rather than duplicates. *events.EventBus, *activity.Log and
	// *activity.AlertLog satisfy them directly.
	Events   scanning.EventPublisher
	Activity scanning.ActivityTracker
	Alerts   scanning.AlertRecorder
	// RecordStoreWriteError escalates a failed store write to a persistent
	// operator alert when the error looks like disk exhaustion. Owned by the
	// composition root because classification needs the storage engine and
	// the same escalation serves the backup and poll-heartbeat writes.
	// Nil-safe; omit to skip the escalation.
	RecordStoreWriteError func(err error)
	// Stops registers the graceful stop callback of the running full scan;
	// scheduled scans register too (stoppable by admins).
	Stops               *activity.StopRegistry
	ShowSkipCache       *showskip.Cache
	StateFunc           func() *LiveState
	ScanningFlag        *atomic.Bool
	DeleteSubtitleFiles func(paths []string, source string)
}

Deps holds all dependencies for the scheduler.

type LiveState

type LiveState struct {
	Cfg       scanning.ScanCfg
	Engine    scanning.ScanEngine
	Sonarr    scanning.ScanSonarrClient
	Radarr    scanning.ScanRadarrClient
	Providers []provider.Provider
}

LiveState holds the live state needed by the scheduler.

Every field is typed as scanning's own interface, for the same reason Deps.ScanDB is. The scheduler reads exactly ONE of the 37 values the config offers — Search(), for the scan interval and the upgrade flag it logs — reads nothing at all off the arr clients, and otherwise only carries the values into scanning.LiveState. A separate declaration here would have to be assignable to scanning's surface anyway, so it could only drift.

type ReconcileMetrics added in v0.1.54

type ReconcileMetrics interface {
	RecordReconcile(deleted int, reset int64, dur time.Duration)
}

ReconcileMetrics is the narrow observability interface for reconcile passes. The concrete *obs.Metrics satisfies this via structural typing.

type Store

type Store interface {
	ReconcileState(ctx context.Context) (subflux.ReconcileResult, error)
	Stats(ctx context.Context) (downloads, attempts int, err error)
}

Store is the two rows RunDBMaintenance touches: the reconcile pass and the aggregate counts it logs afterwards. Two of the 36 methods the store offers, which is why this is declared here and not taken as a wide type.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL