oneparallel

package module
v0.0.0-...-656dd94 Latest Latest
Warning

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

Go to latest
Published: Oct 18, 2025 License: MIT Imports: 21 Imported by: 0

README

oneparallel

Human-friendly parallelization tool similar to GNU/Moreutils Parallel.

asciicast

Documentation

Index

Constants

View Source
const MaxLineBufferHeight = 128

MaxLineBufferHeight is the maximum number of lines that can be buffered in the LineBuffer.

View Source
const TimeTakenAccuracy = time.Millisecond

TimeTakenAccuracy is the accuracy for displaying the time taken for a job. This is only useful for time.Duration.String.

Variables

This section is empty.

Functions

func QuotedArgs

func QuotedArgs(args []string) string

QuotedArgs returns a string representation of the arguments, each quoted if needed. It is similar to strconv.Quote.

Types

type ExecJob

type ExecJob struct {
	exec.Cmd
	// contains filtered or unexported fields
}

ExecJob is a job that wraps an exec.Cmd.

func NewExecJob

func NewExecJob(cmd *exec.Cmd) *ExecJob

NewExecJob creates a new ExecJob.

func NewExecJobs

func NewExecJobs(cmds ...*exec.Cmd) []*ExecJob

NewExecJobs creates a new ExecJob for each command.

func (*ExecJob) SetCustomString

func (j *ExecJob) SetCustomString(s string)

SetCustomString sets a custom string representation for the job.

func (*ExecJob) Start

func (j *ExecJob) Start() error

Start starts the job and returns an error if it fails to start.

func (*ExecJob) Stop

func (j *ExecJob) Stop() error

Stop stops the job and returns an error if it fails to stop. It first tries to SIGINT the process, but if it's called again, it will SIGKILL the process.

It is safe to call Stop concurrently.

func (*ExecJob) String

func (j *ExecJob) String() string

String returns a string representation of the job.

type FinalizedJobs

type FinalizedJobs []*JobResultMessage

FinalizedJobs contains the results of jobs. It is always of length equal to the number of jobs that have been run, but jobs that have not yet completed will have a nil value in the slice.

func (FinalizedJobs) Errors

func (j FinalizedJobs) Errors() []error

Errors collects all the errors from the job result messages in the slice.

func (FinalizedJobs) HasError

func (j FinalizedJobs) HasError() bool

HasError checks if any of the job result messages in the slice contain an error.

func (FinalizedJobs) IsDone

func (j FinalizedJobs) IsDone() bool

IsDone checks if all the job result messages in the slice are done, meaning there is no nil values.

func (FinalizedJobs) NumFinishedJobs

func (j FinalizedJobs) NumFinishedJobs() int

NumFinishedJobs counts the number of jobs that have completed.

type Job

type Job interface {
	fmt.Stringer
	StdoutPipe() (io.ReadCloser, error)
	StderrPipe() (io.ReadCloser, error)
	// Start initiates the job and returns an error if it fails to start.
	Start() error
	// Stop stops the job and returns an error if it fails to stop.
	Stop() error
	// Wait blocks until the job completes and returns an error if it fails.
	Wait() error
}

Job defines the interface for a job that can be run concurrently. It is defined as a subset of the standard library's os/exec.Cmd interface.

type JobLimiter

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

JobLimiter is a simple semaphore implementation that can be used to limit the number of concurrent jobs running at any given time.

A zero value JobLimiter will not limit the number of concurrent jobs.

func NewJobLimiter

func NewJobLimiter(limit int) JobLimiter

NewJobLimiter creates a new JobLimiter.

func (JobLimiter) Acquire

func (j JobLimiter) Acquire(ctx context.Context) (release func(), err error)

Acquire acquires a slot in the semaphore. If the limit has been reached, this will block until a slot becomes available.

type JobResultMessage

type JobResultMessage struct {
	Job       *JobRunner
	Error     error
	TimeTaken time.Duration
}

JobResultMessage is a message that contains the result of a job.

func (*JobResultMessage) HasError

func (j *JobResultMessage) HasError() bool

HasError returns true if the job has an error.

func (*JobResultMessage) IsDone

func (j *JobResultMessage) IsDone() bool

IsDone returns true if the job has finished running.

func (*JobResultMessage) IsStarted

func (j *JobResultMessage) IsStarted() bool

IsStarted returns true if the job has started running. A finished job is still considered started, so this will return true.

type JobRunner

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

JobRunner is a running Job instance.

func NewJobRunner

func NewJobRunner(job Job, id string, opts JobRunnerOpts) *JobRunner

NewJobRunner creates a new JobRunner.

func (*JobRunner) Init

func (j *JobRunner) Init() tea.Cmd

func (*JobRunner) SetHeight

func (j *JobRunner) SetHeight(height int) tea.Cmd

SetHeight sets the height of the job runner's line buffer. The height must be at least 1.

func (*JobRunner) Stop

func (j *JobRunner) Stop() tea.Cmd

Stop signals the job to stop running.

func (*JobRunner) Update

func (j *JobRunner) Update(msg tea.Msg) (*JobRunner, tea.Cmd)

func (*JobRunner) View

func (j *JobRunner) View() string

type JobRunnerOpts

type JobRunnerOpts struct {
	JobLimiter      JobLimiter
	LastLines       int
	OutputDir       string
	CombinedOutputs bool
}

type JobRunners

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

JobRunners is a collection of JobRunner instances.

func NewJobRunners

func NewJobRunners[JobT Job](jobs []JobT, opts JobRunnerOpts) JobRunners

NewJobRunners creates a slice of JobRunner instances from a slice of Job.

func (JobRunners) Finalize

func (j JobRunners) Finalize() (FinalizedJobs, bool)

Finalize returns the job results if all jobs are done. If not, it returns nil and false. If all jobs are done, it returns the results and true.

func (JobRunners) Init

func (j JobRunners) Init() tea.Cmd

func (JobRunners) SetJobHeight

func (j JobRunners) SetJobHeight(height int) tea.Cmd

SetJobHeight returns a command that sets the height for each job runner. It overrides [SetTotalHeight].

func (JobRunners) SetTotalHeight

func (j JobRunners) SetTotalHeight(totalHeight int) tea.Cmd

SetTotalHeight returns a command that sets the total height for all the job runners. It overrides [SetJobHeight].

func (JobRunners) Stop

func (j JobRunners) Stop() tea.Cmd

Stop returns a tea.Cmd that will stop all the jobs in the JobRunners collection.

func (JobRunners) Update

func (j JobRunners) Update(msg tea.Msg) (JobRunners, tea.Cmd)

func (JobRunners) View

func (j JobRunners) View() string

type JobStopMessage

type JobStopMessage struct {
	Job *JobRunner
}

JobStopMessage is a message that is sent to signal a job to stop running.

type LineBuffer

type LineBuffer struct {
	Width  int
	Height int
	// contains filtered or unexported fields
}

LineBuffer is a UI element that buffers the last few lines of text.

func (LineBuffer) Init

func (l LineBuffer) Init() tea.Cmd

func (LineBuffer) LineWriter

func (l LineBuffer) LineWriter() LineWriter

LineWriter returns a LineWriter that writes lines to [l].

func (LineBuffer) SetHeight

func (l LineBuffer) SetHeight(height int) tea.Cmd

SetHeight sets the height of the line buffer. The height can not be higher than

func (LineBuffer) Update

func (l LineBuffer) Update(msg tea.Msg) (LineBuffer, tea.Cmd)

func (LineBuffer) View

func (l LineBuffer) View() string

View returns the buffered lines as a single string.

type LineWriter

type LineWriter interface {
	WriteLine([]byte) error
}

LineWriter is an interface for writing lines of text. It is used to write lines to different outputs, such as a buffer or a file.

Directories

Path Synopsis
cmd
oneparallel command
internal

Jump to

Keyboard shortcuts

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