app

package
v0.6.1 Latest Latest
Warning

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

Go to latest
Published: Apr 1, 2026 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ApplyToConfig added in v0.6.1

func ApplyToConfig(base *config.Config, runtime *RuntimeSettings) *config.Config

ApplyToConfig applies runtime-editable settings on top of bootstrap config.

func ValidateArrIntegrations added in v0.6.1

func ValidateArrIntegrations(integrations []ArrIntegrationRuntimeSettings) error

Types

type AggregatorDownloadResult added in v0.6.1

type AggregatorDownloadResult struct {
	Release     *domain.Release
	Reader      io.ReadCloser
	RedirectURL string
}

type AggregatorModule added in v0.6.1

type AggregatorModule interface {
	Search(ctx context.Context, req SearchRequest) ([]*domain.Release, error)
	PrepareDownload(ctx context.Context, id string) (*AggregatorDownloadResult, error)
}

type ArrIntegrationRuntimeSettings added in v0.6.1

type ArrIntegrationRuntimeSettings struct {
	ID         string `json:"id"`
	Kind       string `json:"kind"`
	Enabled    bool   `json:"enabled"`
	BaseURL    string `json:"base_url"`
	APIKey     string `json:"api_key"`
	ClientName string `json:"client_name,omitempty"`
	Category   string `json:"category,omitempty"`
}

type ArrNotifier added in v0.6.0

type ArrNotifier interface {
	NotifyQueueTerminal(ctx context.Context, item *domain.QueueItem) error
}

type BlobStore added in v0.6.0

type BlobStore interface {
	// Blobs: File System
	GetNZBReader(key string) (io.ReadCloser, error)
	CreateNZBWriter(key string) (io.WriteCloser, error)
	SaveNZBAtomically(key string, data []byte) error
	Exists(key string) bool
}

type Context

type Context struct {
	BootstrapConfig *config.Config
	Config          *config.Config
	Logger          *logger.Logger

	// High-level interfaces for services to use
	NNTP              NNTPManager
	Aggregator        IndexerAggregator
	Resolver          ReleaseResolver
	UsenetIndexer     UsenetIndexerService
	Processor         Processor
	Downloader        Downloader
	Queue             QueueManager
	NZBParser         NZBParser
	JobStore          JobStore
	QueueFileStore    QueueFileStore
	BlobStore         BlobStore
	PayloadFetcher    PayloadFetcher
	PayloadCacheStore PayloadCacheStore
	SettingsStore     SettingsStore
	PGIndexStore      UsenetIndexStore
	ArrNotifier       ArrNotifier

	DownloaderModule DownloaderModule
	AggregatorModule AggregatorModule
	SettingsAdmin    SettingsAdmin

	ExtractionEnabled bool
	// contains filtered or unexported fields
}

Context hold the core environment and shared resources for GoNZB. It acts as the "Single Source of Truth" for the application state.

func NewContext

func NewContext(cfg *config.Config, log *logger.Logger) (*Context, error)

NewContext returns the shared application container. Concrete runtime construction lives in internal/runtime/wiring.

func (*Context) AddCloser added in v0.6.0

func (ctx *Context) AddCloser(c io.Closer)

allow runtime wiring (from main) to register additional closers.

func (*Context) Close added in v0.5.0

func (ctx *Context) Close()

func (*Context) CurrentConfig added in v0.6.1

func (ctx *Context) CurrentConfig() *config.Config

func (*Context) RegisterRuntimeModules added in v0.6.1

func (ctx *Context) RegisterRuntimeModules(modules ...RuntimeModule)

func (*Context) RuntimeModule added in v0.6.1

func (ctx *Context) RuntimeModule(name string) RuntimeModule

func (*Context) RuntimeModules added in v0.6.1

func (ctx *Context) RuntimeModules() []RuntimeModule

type DownloadRuntimeSettings added in v0.6.1

type DownloadRuntimeSettings struct {
	OutDir            string   `json:"out_dir"`
	CompletedDir      string   `json:"completed_dir"`
	CleanupExtensions []string `json:"cleanup_extensions"`
}

type Downloader added in v0.5.0

type Downloader interface {
	// The engine's ability to process a specific item
	Download(ctx context.Context, item *domain.QueueItem) error
	RenderCLIProgress(item *domain.QueueItem, speedMbps float64, final bool)
	SetProgressHandler(fn func(*domain.QueueItem))
}

type DownloaderCommands added in v0.6.1

type DownloaderCommands interface {
	EnqueueByReleaseID(ctx context.Context, releaseID, title string) (*domain.QueueItem, error)
	EnqueueNZB(ctx context.Context, filename string, file io.Reader) (*domain.QueueItem, error)
	EnqueueNZBWithCategory(ctx context.Context, filename, category string, file io.Reader) (*domain.QueueItem, error)
	Cancel(id string) bool
	CancelMany(ids []string) int
	DeleteMany(ctx context.Context, ids []string) (int64, error)
	ClearHistory(ctx context.Context) (int64, error)
	Pause() bool
	Resume() bool
}

type DownloaderModule added in v0.6.1

type DownloaderModule interface {
	Commands() DownloaderCommands
	Queries() DownloaderQueries
}

type DownloaderQueries added in v0.6.1

type DownloaderQueries interface {
	ListActive() []*domain.QueueItem
	ListHistory(ctx context.Context, status string, limit, offset int) ([]*domain.QueueItem, int, error)
	GetActiveItem() *domain.QueueItem
	GetItem(ctx context.Context, id string) (*domain.QueueItem, error)
	GetItemFiles(ctx context.Context, id string) ([]*domain.DownloadFile, error)
	GetItemEvents(ctx context.Context, id string) ([]*domain.QueueItemEvent, error)
	IsPaused() bool
}

type IndexerAggregator added in v0.6.0

type IndexerAggregator interface {
	SearchAll(ctx context.Context, query string) ([]*domain.Release, error)
	SearchAllWithRequest(ctx context.Context, req SearchRequest) ([]*domain.Release, error)
	GetNZB(ctx context.Context, res *domain.Release) (io.ReadCloser, error)
	GetResultByID(ctx context.Context, id string) (*domain.Release, error)
}

Manager defines the contract for our NZB search and download engine.

type IndexerRuntimeSettings added in v0.6.1

type IndexerRuntimeSettings struct {
	ID       string `json:"id"`
	BaseURL  string `json:"base_url"`
	APIPath  string `json:"api_path"`
	APIKey   string `json:"api_key"`
	Redirect bool   `json:"redirect"`
}

type IndexingRuntimeSettings added in v0.6.1

type IndexingRuntimeSettings struct {
	Newsgroups              []string `json:"newsgroups,omitempty"`
	ScrapeBatchSize         int64    `json:"scrape_batch_size,omitempty"`
	ScheduleIntervalMinutes int      `json:"schedule_interval_minutes,omitempty"`
}

type JobStore added in v0.6.0

type JobStore interface {
	// Downloader Queue: SQLite
	SaveQueueItem(ctx context.Context, item *domain.QueueItem) error
	GetQueueItem(ctx context.Context, id string) (*domain.QueueItem, error)
	GetQueueItems(ctx context.Context) ([]*domain.QueueItem, error)
	GetActiveQueueItems(ctx context.Context) ([]*domain.QueueItem, error)
	DeleteQueueItems(ctx context.Context, ids []string) (int64, error)
	ClearQueueHistory(ctx context.Context, statuses []domain.JobStatus) (int64, error)
	SaveQueueEvent(ctx context.Context, ev *domain.QueueItemEvent) error
	GetQueueEvents(ctx context.Context, queueID string) ([]*domain.QueueItemEvent, error)
	ResetStuckQueueItems(ctx context.Context, newStatus domain.JobStatus, oldStatuses ...domain.JobStatus) error

	// store liveness + schema handshake.
	Ping(ctx context.Context) error
	SchemaVersion(ctx context.Context) (int, error)
	ExpectedSchemaVersion() int
	ValidateSchema(ctx context.Context) error
}

JobStore defines downloader queue/event/history persistence.

type NNTPManager

type NNTPManager interface {
	// This allows the engine to call the manager without importing the nntp package
	Fetch(ctx context.Context, seg *domain.Segment, groups []string) (io.Reader, error)
	TotalCapacity() int
	Close() error // allows idle runtime swaps on settings reload
}

type NZBParser added in v0.5.0

type NZBParser interface {
	ParseFile(nzbPath string) (*nzb.Model, error)
	Parse(r io.Reader) (*nzb.Model, error)
}

type PayloadCacheStore added in v0.6.0

type PayloadCacheStore interface {
	GetNZBReader(key string) (io.ReadCloser, error)
	CreateNZBWriter(key string) (io.WriteCloser, error)
	SaveNZBAtomically(key string, data []byte) error
	Exists(key string) bool
}

type PayloadFetcher added in v0.6.0

type PayloadFetcher interface {
	GetNZB(ctx context.Context, sourceKind string, res *domain.Release) (io.ReadCloser, error)
}

payload fetch now routes by persisted source kind.

type Processor

type Processor interface {
	// processor now needs the queue item so it can use a per-job work dir
	Prepare(ctx context.Context, item *domain.QueueItem, nzbModel *nzb.Model, nzbFilename string) (*domain.PreparationResult, error)
	Finalize(ctx context.Context, tasks []*domain.DownloadFile) error
	PostProcess(ctx context.Context, item *domain.QueueItem, tasks []*domain.DownloadFile) error
}

type QueueAddRequest added in v0.6.0

type QueueAddRequest struct {
	SourceKind      string
	SourceReleaseID string
	Release         *domain.Release
	Title           string
}

explicit queue enqueue contract so downloader does not infer source provenance.

type QueueFileStore added in v0.6.0

type QueueFileStore interface {
	SaveQueueItemFiles(ctx context.Context, queueItemID string, files []*domain.DownloadFile) error
	GetQueueItemFiles(ctx context.Context, queueItemID string) ([]*domain.DownloadFile, error)
}

downloader-owned queue item file metadata

type QueueManager added in v0.5.0

type QueueManager interface {
	Start(ctx context.Context)
	Add(ctx context.Context, req QueueAddRequest) (*domain.QueueItem, error)
	GetActiveItem() *domain.QueueItem
	GetItem(ctx context.Context, id string) (*domain.QueueItem, bool)
	GetAllItems() []*domain.QueueItem
	Cancel(id string) bool
	Delete(id string) bool
	Stop()

	Pause() bool
	Resume() bool
	IsPaused() bool

	HydrateItem(ctx context.Context, item *domain.QueueItem) error
	UpdateStatus(ctx context.Context, item *domain.QueueItem, status domain.JobStatus)
	ReloadRuntime(appCtx *Context) // refresh future-job dependencies after settings reload
}

type ReleaseResolver added in v0.6.0

type ReleaseResolver interface {
	GetRelease(ctx context.Context, sourceKind, sourceReleaseID string) (*domain.Release, error)
	GetNZB(ctx context.Context, sourceKind string, res *domain.Release) (io.ReadCloser, error)
}

resolver routes by source kind instead of assuming aggregator-only resolution.

type RuntimeCheck added in v0.6.1

type RuntimeCheck struct {
	Name   string
	OK     bool
	Detail string
}

type RuntimeModule added in v0.6.1

type RuntimeModule interface {
	Name() string
	Enabled() bool
	Build(ctx context.Context) error
	Start(ctx context.Context) error
	Reload(ctx context.Context) error
	Close() error
	ReadinessChecks(ctx context.Context) []RuntimeCheck
}

type RuntimeSettings added in v0.6.1

type RuntimeSettings struct {
	Servers         []ServerRuntimeSettings         `json:"servers,omitempty"`
	Indexers        []IndexerRuntimeSettings        `json:"indexers,omitempty"`
	Download        *DownloadRuntimeSettings        `json:"download,omitempty"`
	Indexing        *IndexingRuntimeSettings        `json:"indexing,omitempty"`
	ArrIntegrations []ArrIntegrationRuntimeSettings `json:"arr_integrations,omitempty"`
	Revision        int64                           `json:"revision,omitempty"`
}

func ApplyPatch added in v0.6.1

func ApplyPatch(current *RuntimeSettings, patch *RuntimeSettingsPatch) *RuntimeSettings

ApplyPatch applies an incoming patch to the current runtime settings.

func CloneRuntimeSettings added in v0.6.1

func CloneRuntimeSettings(in *RuntimeSettings) *RuntimeSettings

CloneRuntimeSettings returns a deep copy of runtime settings.

func FromConfig added in v0.6.1

func FromConfig(cfg *config.Config) *RuntimeSettings

FromConfig derives editable runtime state from current effective config.

func RedactedCopy added in v0.6.1

func RedactedCopy(in *RuntimeSettings) *RuntimeSettings

RedactedCopy removes secrets before returning settings externally.

type RuntimeSettingsPatch added in v0.6.1

type RuntimeSettingsPatch struct {
	Servers         *[]ServerRuntimeSettings         `json:"servers,omitempty"`
	Indexers        *[]IndexerRuntimeSettings        `json:"indexers,omitempty"`
	Download        *DownloadRuntimeSettings         `json:"download,omitempty"`
	Indexing        *IndexingRuntimeSettings         `json:"indexing,omitempty"`
	ArrIntegrations *[]ArrIntegrationRuntimeSettings `json:"arr_integrations,omitempty"`
}

type SearchRequest added in v0.6.1

type SearchRequest struct {
	Type string

	Query string

	IMDbID   string
	TVDBID   string
	TVMazeID string
	RageID   string
	Season   string
	Episode  string
	Genre    string
}

type ServerRuntimeSettings added in v0.6.1

type ServerRuntimeSettings struct {
	ID            string `json:"id"`
	Host          string `json:"host"`
	Port          int    `json:"port"`
	Username      string `json:"username"`
	Password      string `json:"password"`
	TLS           bool   `json:"tls"`
	MaxConnection int    `json:"max_connections"`
	Priority      int    `json:"priority"`
}

type SettingsAdmin added in v0.6.1

type SettingsAdmin interface {
	Get(ctx context.Context) (*RuntimeSettings, error)
	Update(ctx context.Context, patch *RuntimeSettingsPatch) (*RuntimeSettings, error)
}

type SettingsStore added in v0.6.0

type SettingsStore interface {
	LoadEffectiveSettings(ctx context.Context, base *config.Config) (*config.Config, error)
	GetRuntimeSettings(ctx context.Context, base ...*config.Config) (*RuntimeSettings, error)
	UpdateSettings(ctx context.Context, next *RuntimeSettings) error
	WatchSettingsChanges(ctx context.Context) (<-chan struct{}, error)

	// store liveness + schema handshake.
	Ping(ctx context.Context) error
	SchemaVersion(ctx context.Context) (int, error)
	ExpectedSchemaVersion() int
	ValidateSchema(ctx context.Context) error
}

Runtime settings

type UsenetIndexCatalog added in v0.6.0

type UsenetIndexCatalog interface {
	GetCatalogReleaseByID(ctx context.Context, releaseID string) (*domain.Release, error)
}

minimal PG catalog boundary for Milestone 7 resolver routing.

type UsenetIndexStore added in v0.6.1

type UsenetIndexStore interface {
	UsenetIndexCatalog

	Ping(ctx context.Context) error
	ValidateSchema(ctx context.Context) error

	ListCatalogReleaseFiles(ctx context.Context, releaseID string) ([]pgindex.CatalogReleaseFile, error)
	ListCatalogReleaseFileArticles(ctx context.Context, releaseFileID int64) ([]pgindex.CatalogArticleRef, error)
	ListCatalogReleaseNewsgroups(ctx context.Context, releaseID string) ([]string, error)
	UpsertNZBCache(ctx context.Context, releaseID, generationStatus, hashSHA256, lastError string) error

	EnsureProvider(ctx context.Context, providerKey, displayName string) (int64, error)
	EnsureNewsgroup(ctx context.Context, groupName string) (int64, error)
	StartScrapeRun(ctx context.Context, providerID int64) (int64, error)
	FinishScrapeRun(ctx context.Context, runID int64, status, errorText string) error
	GetLatestCheckpoint(ctx context.Context, providerID, newsgroupID int64) (int64, error)
	UpsertLatestCheckpoint(ctx context.Context, providerID, newsgroupID, lastArticleNumber int64) error
	GetBackfillCheckpoint(ctx context.Context, providerID, newsgroupID int64) (int64, error)
	UpsertBackfillCheckpoint(ctx context.Context, providerID, newsgroupID, backfillArticleNumber int64) error
	InsertArticleHeaders(ctx context.Context, providerID, newsgroupID int64, headers []pgindex.ArticleHeader) (int64, error)

	ListUnassembledArticleHeaders(ctx context.Context, limit int) ([]pgindex.AssemblyCandidate, error)
	EnsurePoster(ctx context.Context, posterName string) (int64, error)
	LinkArticlePoster(ctx context.Context, articleHeaderID, posterID int64) error
	UpsertBinary(ctx context.Context, in pgindex.BinaryRecord) (int64, error)
	UpsertBinaryPart(ctx context.Context, in pgindex.BinaryPartRecord) error
	RefreshBinaryStats(ctx context.Context, binaryID int64) error

	ListReleaseCandidates(ctx context.Context, limit int) ([]pgindex.ReleaseCandidate, error)
	ListBinariesForReleaseCandidate(ctx context.Context, providerID, newsgroupID int64, releaseKey string) ([]pgindex.BinarySummary, error)
	ListBinaryPartArticles(ctx context.Context, binaryID int64) ([]pgindex.ReleaseFileArticleRecord, error)
	UpsertRelease(ctx context.Context, in pgindex.ReleaseRecord) (string, error)
	ReplaceReleaseFiles(ctx context.Context, releaseID string, files []pgindex.ReleaseFileRecord) error
	ReplaceReleaseNewsgroups(ctx context.Context, releaseID string, newsgroupIDs []int64) error
}

current PG-backed store surface used by resolver, indexing runtime, health checks, and smoke tests. This keeps Context from depending on the concrete *pgindex.Store type directly.

type UsenetIndexerService added in v0.6.0

type UsenetIndexerService interface {
	ScrapeOnce(ctx context.Context) error
	ScrapeLatestOnce(ctx context.Context) error
	ScrapeBackfillOnce(ctx context.Context) error
	AssembleOnce(ctx context.Context) error
	ReleaseOnce(ctx context.Context) error
	RunPipelineOnce(ctx context.Context) error
	Start(ctx context.Context, interval time.Duration) error
}

Jump to

Keyboard shortcuts

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