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 ¶
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.
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 ¶
Spawn starts a background process for the given command.
- Resolves the working directory and jobs storage location
- Generates a unique job ID
- Creates a log file for the background process
- Spawns the background process with the given command/flags
- Creates a job record for tracking
- 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.