externalprograms

package
v1.14.1 Latest Latest
Warning

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

Go to latest
Published: Feb 23, 2026 License: GPL-2.0 Imports: 16 Imported by: 0

Documentation

Overview

Package externalprograms provides a unified service for executing external programs with torrent data. It is used by automations, cross-seed, and the API handler.

Index

Constants

View Source
const ActivityActionExternalProgram = "external_program"

Activity action constant for external program execution. Success/failure is indicated via the Outcome field, following the same pattern as other actions.

Variables

This section is empty.

Functions

This section is empty.

Types

type ExecuteRequest

type ExecuteRequest struct {
	// ProgramID is used to fetch the program from the store.
	// Either ProgramID or Program must be provided.
	ProgramID int
	// Program is an optional pre-loaded program configuration.
	// When provided, ProgramID is ignored and no database lookup is performed.
	Program *models.ExternalProgram

	Torrent    *qbt.Torrent
	InstanceID int

	// Optional: automation context for activity logging
	RuleID   *int
	RuleName string
}

ExecuteRequest contains all parameters needed to execute an external program.

func (ExecuteRequest) Validate

func (r ExecuteRequest) Validate() error

Validate checks that the request has all required fields.

type ExecuteResult

type ExecuteResult struct {
	Success bool
	Message string
	Error   error
}

ExecuteResult contains the result of an execution attempt.

func FailureResult

func FailureResult(err error) ExecuteResult

FailureResult creates a failed execution result.

func FailureResultWithMessage

func FailureResultWithMessage(err error, message string) ExecuteResult

FailureResultWithMessage creates a failed execution result with an additional message.

func SuccessResult

func SuccessResult(message string) ExecuteResult

SuccessResult creates a successful execution result.

type Service

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

Service provides unified external program execution for all consumers.

func NewService

func NewService(
	programStore *models.ExternalProgramStore,
	activityStore *models.AutomationActivityStore,
	config *domain.Config,
) *Service

NewService creates a new external programs service. activityStore may be nil if activity logging is not needed.

func (*Service) Execute

func (s *Service) Execute(ctx context.Context, req ExecuteRequest) ExecuteResult

Execute runs an external program asynchronously with the given torrent data. It returns immediately after launching the program (fire-and-forget).

The program can be provided in two ways:

  • By ID: Set ProgramID to fetch the program from the store
  • Directly: Set Program to use a pre-loaded program configuration

WARNING: This function spawns processes without any rate limiting or process count limits. Callers should be aware that rapid invocations (e.g., from automations matching many torrents) can spawn a large number of concurrent processes. If the external program runs indefinitely or takes a long time to complete, this can exhaust system resources. Consider implementing caller-side throttling or ensuring the external programs exit promptly.

func (*Service) IsPathAllowed

func (s *Service) IsPathAllowed(programPath string) bool

IsPathAllowed checks if the program path is allowed by the allowlist.

Jump to

Keyboard shortcuts

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