scheduler

package
v0.1.151 Latest Latest
Warning

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

Go to latest
Published: Jul 19, 2026 License: GPL-2.0, GPL-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 OIDCStateTTL = 10 * time.Minute

OIDCStateTTL is how long an OIDC authorization flow can remain pending before garbage collection.

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.ActivitySource) (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 api.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           *serveradapter.ScanEventAdapter
	Activity         *serveradapter.ActivityAdapter
	Alerts           *serveradapter.AlertAdapter
	// 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       api.ConfigProvider
	Engine    api.SearchEngine
	Sonarr    api.SonarrClient
	Radarr    api.RadarrClient
	Providers []api.Provider
}

LiveState holds the live state needed by the scheduler.

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 *metrics.Metrics satisfies this via structural typing.

type Store

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

Store is the narrow store interface used by RunDBMaintenance.

Jump to

Keyboard shortcuts

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