detach

package
v0.1.5 Latest Latest
Warning

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

Go to latest
Published: Feb 24, 2026 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Overview

Package detach provides background process management for CLI operations.

This package handles the orchestration of detached/background operations, separating the application-level concerns (job tracking, process lifecycle) from the CLI presentation layer.

Index

Constants

View Source
const DefaultJobTimeout = 24 * time.Hour

DefaultJobTimeout is the maximum duration a background job can run before being marked as timed out. This prevents goroutine leaks from hung processes.

Variables

This section is empty.

Functions

func BuildPullFlags

func BuildPullFlags(env, workspace, output, digest, releaseID, version string, force, verify bool) []string

BuildPullFlags builds the flag list for a detached pull command. Centralizes pull option → CLI flag conversion for use by CLI and tests.

func BuildPushFlags

func BuildPushFlags(env, workspace, notes string, labels, runsPaths []string, noRuns, nonInteractive bool) []string

BuildPushFlags builds the flag list for a detached push command. Centralizes push option → CLI flag conversion for use by CLI and tests.

Types

type Options

type Options struct {
	// Command is the CLI command name (e.g., "push", "pull").
	Command string

	// Args are the command arguments (e.g., remote name, pack path).
	Args []string

	// Flags are additional flags to pass to the background command.
	// These should NOT include --detach (would cause infinite loop).
	Flags []string

	// WorkingDir is the working directory for the background process.
	// If empty, uses the project root or current directory.
	WorkingDir string

	// JobsDir is the directory for job storage.
	// If empty, uses .epack/jobs under project root.
	JobsDir string
}

Options configures a detached operation.

type Result

type Result struct {
	// JobID is the unique job identifier.
	JobID string

	// PID is the process ID of the background process.
	PID int

	// LogPath is the path to the job log file.
	LogPath string

	// Job is the created job record.
	Job *jobs.Job
}

Result contains the result of spawning a detached process.

func Spawn

func Spawn(opts Options) (*Result, error)

Spawn starts a background process for the given command.

  1. Resolves the working directory and jobs storage location
  2. Generates a unique job ID
  3. Creates a log file for the background process
  4. Spawns the background process with the given command/flags
  5. Creates a job record for tracking
  6. Starts a goroutine to update job status when the process exits

The caller should ensure that --detach is NOT included in Flags to avoid infinite recursion.

Jump to

Keyboard shortcuts

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