postie

package
v0.0.31 Latest Latest
Warning

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

Go to latest
Published: Jul 4, 2026 License: MIT Imports: 23 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Postie

type Postie struct {
	// contains filtered or unexported fields
}

func New

func New(
	ctx context.Context,
	cfg config.Config,
	poolManager *pool.Manager,
	jobProgress progress.JobProgress,
	queue QueueInterface,
) (*Postie, error)

New creates a Postie that owns a private transfer runtime. It is retained as a compatibility entry point for the CLI and external package users; the processor path uses NewWithRuntime to share one process-wide runtime across all jobs.

func NewWithRuntime added in v0.0.30

func NewWithRuntime(
	ctx context.Context,
	cfg config.Config,
	poolManager *pool.Manager,
	jobProgress progress.JobProgress,
	queue QueueInterface,
	rt *Runtime,
	transferID string,
) (*Postie, error)

NewWithRuntime creates a Postie that borrows shared resources from rt. When rt is nil a private PAR2 scheduler is created honouring the configured par2.max_concurrent_jobs, preserving standalone behaviour. transferID binds this job's durable manifests; when empty (or rt has no store) manifest recording is disabled.

func (*Postie) CleanupPar2Files added in v0.0.29

func (p *Postie) CleanupPar2Files(ctx context.Context, sourceFile fileinfo.FileInfo)

CleanupPar2Files removes PAR2 files for the given source file This method can be called when a job fails permanently to clean up orphaned PAR2 files

func (*Postie) Close added in v0.0.6

func (p *Postie) Close()

func (*Postie) ExecutePostUploadScript added in v0.0.29

func (p *Postie) ExecutePostUploadScript(ctx context.Context, nzbPath string, sourcePath string, itemID string) error

ExecutePostUploadScript executes the post-upload script for a completed item This should be called after the file has been marked as completed in the database

func (*Postie) Post

func (p *Postie) Post(ctx context.Context, files []fileinfo.FileInfo, rootDir string, outputDir string, forceFolderMode bool) (nzbPath string, retErr error)

func (*Postie) SetDeleteOriginal added in v0.0.30

func (p *Postie) SetDeleteOriginal(v bool)

SetDeleteOriginal records whether the job's original files should be deleted after the durable verification service confirms the upload. Must be called before Post. No effect in standalone mode (deletion is handled inline there).

type QueueInterface added in v0.0.29

type QueueInterface interface {
	UpdateScriptStatus(ctx context.Context, itemID string, status string, retryCount int, lastError string, nextRetryAt *time.Time, firstFailureAt *time.Time) error
	MarkScriptCompleted(ctx context.Context, itemID string) error
}

QueueInterface defines the queue methods needed by Postie

type Runtime added in v0.0.30

type Runtime struct {
	// contains filtered or unexported fields
}

Runtime owns the process-wide transfer resources shared across all upload jobs. Today it holds the PAR2 scheduler; later phases extend it with the upload engine, durable verification service, shared throttle, and global upload-buffer budget.

The Processor creates one Runtime during initialization and closes it during shutdown. Each per-job Postie borrows these shared resources (via NewWithRuntime) instead of creating its own, which is what makes the limits process-wide rather than per queue job.

func NewRuntime added in v0.0.30

func NewRuntime(ctx context.Context, cfg config.Config, poolManager *pool.Manager, store *transferstore.Store, manifestDir string, scriptQueue QueueInterface) (*Runtime, error)

NewRuntime builds the shared transfer runtime from cfg. poolManager may be nil; when it is (or when no upload connections are advertised) the upload engine is left unset and jobs fall back to standalone, unbounded behaviour. store and manifestDir enable durable manifest recording; when store is nil jobs run without manifests (standalone). It is safe to call with a cfg whose PAR2 settings are unset; the PAR2 scheduler then defaults to a single job.

func (*Runtime) Close added in v0.0.30

func (r *Runtime) Close() error

Close releases runtime-owned resources. It is safe to call on a nil Runtime and safe to call more than once.

func (*Runtime) DurableVerificationEnabled added in v0.0.30

func (r *Runtime) DurableVerificationEnabled() bool

DurableVerificationEnabled reports whether durable verification is active (a verification service was created). When true, callers should defer destructive cleanup (delete_original, post-upload script) until the durable service marks the transfer verified, rather than acting at upload completion.

func (*Runtime) Metrics added in v0.0.30

func (r *Runtime) Metrics() RuntimeMetrics

Metrics returns a snapshot of current runtime resource usage. Safe on a nil Runtime (returns the zero value).

func (*Runtime) NewManifestRecorder added in v0.0.30

func (r *Runtime) NewManifestRecorder(transferID string) *transferwriter.Recorder

NewManifestRecorder returns a per-job manifest recorder bound to transferID, or nil when the runtime has no store or transferID is empty (so the poster runs without manifest recording). The concrete type lets the caller both use it as a poster.ManifestSink and call CompleteUpload after posting.

func (*Runtime) Par2Scheduler added in v0.0.30

func (r *Runtime) Par2Scheduler() *par2.Scheduler

Par2Scheduler returns the shared PAR2 scheduler, or nil if r is nil.

func (*Runtime) RunVerification added in v0.0.30

func (r *Runtime) RunVerification(ctx context.Context)

RunVerification runs the durable verification service until ctx is cancelled. It is a no-op (returns immediately) when no service was created (standalone mode or missing store/pool). Intended to be started once as a goroutine.

func (*Runtime) TransferStore added in v0.0.30

func (r *Runtime) TransferStore() *transferstore.Store

TransferStore returns the shared durable transfer store, or nil if none.

func (*Runtime) UploadEngine added in v0.0.30

func (r *Runtime) UploadEngine() *poster.Engine

UploadEngine returns the shared upload engine, or nil if r is nil or no engine was created.

type RuntimeMetrics added in v0.0.30

type RuntimeMetrics struct {
	UploadActiveWorkers int64 `json:"uploadActiveWorkers"`
	UploadQueuedWorkers int64 `json:"uploadQueuedWorkers"`
	UploadWorkerCount   int64 `json:"uploadWorkerCount"`
	UploadReservedBytes int64 `json:"uploadReservedBytes"`
	UploadBudgetBytes   int64 `json:"uploadBudgetBytes"`
	Par2ActiveJobs      int64 `json:"par2ActiveJobs"`
	Par2QueuedJobs      int64 `json:"par2QueuedJobs"`
	Par2Capacity        int   `json:"par2Capacity"`
}

RuntimeMetrics is a point-in-time snapshot of process-wide transfer resource usage, suitable for surfacing in the UI or logs so memory growth can be attributed to a subsystem.

Jump to

Keyboard shortcuts

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