Documentation
¶
Overview ¶
Copyright © 2023 Jonathan Gotti <jgotti at jgotti dot org> SPDX-FileType: SOURCE SPDX-License-Identifier: MIT SPDX-FileCopyrightText: 2023 Jonathan Gotti <jgotti@jgotti.org>
Index ¶
- Constants
- Variables
- func NewPrefixedWriter(buf io.Writer, prefix string) *prefixedWriter
- func SetMaxConcurrentJobs(n int)
- func SetTemplateString(templateString string)
- type Job
- type JobExecutor
- func (e *JobExecutor) AddJob(j interface{}) Job
- func (e *JobExecutor) AddJobCmds(cmds ...*exec.Cmd) *JobExecutor
- func (e *JobExecutor) AddJobDependency(from Job, to Job) *JobExecutor
- func (e *JobExecutor) AddJobFns(fns ...runnableFn) *JobExecutor
- func (e *JobExecutor) AddJobs(jobs ...interface{}) []Job
- func (e *JobExecutor) AddNamedJobCmd(name string, cmd *exec.Cmd) *JobExecutor
- func (e *JobExecutor) AddNamedJobFn(name string, fn runnableFn) *JobExecutor
- func (e *JobExecutor) DagExecute() JobsError
- func (e *JobExecutor) Execute() JobsError
- func (e *JobExecutor) GetDot() string
- func (e *JobExecutor) IsAcyclic() bool
- func (e *JobExecutor) Len() int
- func (e *JobExecutor) OnJobDone(fn jobEventHandler) *JobExecutor
- func (e *JobExecutor) OnJobStart(fn jobEventHandler) *JobExecutor
- func (e *JobExecutor) OnJobsDone(fn jobsEventHandler) *JobExecutor
- func (e *JobExecutor) OnJobsStart(fn jobsEventHandler) *JobExecutor
- func (e *JobExecutor) WithFifoOutput() *JobExecutor
- func (e *JobExecutor) WithInterleavedOutput() *JobExecutor
- func (e *JobExecutor) WithOngoingStatusOutput() *JobExecutor
- func (e *JobExecutor) WithOrderedOutput() *JobExecutor
- func (e *JobExecutor) WithProgressBarOutput(length int, keepOnDone bool, colorEscSeq string) *JobExecutor
- func (e *JobExecutor) WithStartOutput() *JobExecutor
- func (e *JobExecutor) WithStartSummary() *JobExecutor
- type JobList
- type JobsError
- type NamedJob
Constants ¶
const ( JobStatePending = 0 JobStateRunning = 1 JobStateDone = 2 JobStateSucceed = 4 JobStateFailed = 8 )
Variables ¶
var ErrCyclicDependencyDetected = fmt.Errorf("cyclic dependencies detected")
var ErrRequiredJobFailed = fmt.Errorf("required job failed")
var ErrUndefinedTemplate = fmt.Errorf("template is not defined, see jobExecutor.setTemplate")
Functions ¶
func NewPrefixedWriter ¶ added in v2.1.2
func SetMaxConcurrentJobs ¶
func SetMaxConcurrentJobs(n int)
set the default number of concurrent jobs to run default to GOMAXPROCS
func SetTemplateString ¶
func SetTemplateString(templateString string)
Template for all outputs related to jobs It must define the following templates:
- startSummary: which will receive a JobList
- jobStatus: which will receive a single job
- progressReport: which will receive a jobList
- doneReport: which will receive a jobList
Types ¶
type Job ¶ added in v2.1.0
type Job struct {
// contains filtered or unexported fields
}
func (*Job) CombinedOutput ¶ added in v2.1.0
return the combinedOutput of job (only after execution) this is concurrency safe
func (*Job) Err ¶ added in v2.1.0
return the error returned by a job if any (only after execution) this is concurrency safe
func (*Job) Id ¶ added in v2.1.0
return internal job Id, correspond to insertion order in an executor
type JobExecutor ¶
type JobExecutor struct {
// contains filtered or unexported fields
}
func NewExecutorWithTemplate ¶ added in v2.1.0
func NewExecutorWithTemplate(template *template.Template) *JobExecutor
func (*JobExecutor) AddJob ¶ added in v2.1.0
func (e *JobExecutor) AddJob(j interface{}) Job
Add any kind of supported job to the jobExecutor pool and return a Job supported jobs are: - an *exec.Cmd - a runnableFn (func() (string, error)) - a NamedJob any unsupported job type will panic some examples:
// add an *exec.Cmd
cmd := exec.Command("mycommand")
job, err := executor.AddJob(cmd)
// add runnableFn
job, err := executor.AddJob(func() (string, error) {... })
// add named *exec.Cmd
job, err := executor.AddJob(&jobExecutor.NamedJob{"myjob", cmd))
// add named runnableFn
job, err := executor.AddJob(&jobExecutor.NamedJob{"myjob", func() (string, error) {... }})
the returned Job can be used to declare dependencies between Jobs
func (*JobExecutor) AddJobCmds ¶
func (e *JobExecutor) AddJobCmds(cmds ...*exec.Cmd) *JobExecutor
Add multiple job commands to run. This method can be chained.
func (*JobExecutor) AddJobDependency ¶ added in v2.1.0
func (e *JobExecutor) AddJobDependency(from Job, to Job) *JobExecutor
Register "from" job as dependent on "to" job
func (*JobExecutor) AddJobFns ¶
func (e *JobExecutor) AddJobFns(fns ...runnableFn) *JobExecutor
Add one or more job function to run (func() (string, error)). This method can be chained.
func (*JobExecutor) AddJobs ¶ added in v2.1.0
func (e *JobExecutor) AddJobs(jobs ...interface{}) []Job
same as AddJob but for multiple jobs at once it will panic on invalid job, and return a slice of added Jobs
func (*JobExecutor) AddNamedJobCmd ¶
func (e *JobExecutor) AddNamedJobCmd(name string, cmd *exec.Cmd) *JobExecutor
Add a job command and set its output display name. This method can be chained.
func (*JobExecutor) AddNamedJobFn ¶
func (e *JobExecutor) AddNamedJobFn(name string, fn runnableFn) *JobExecutor
Add a job function and set its output display name. This method can be chained.
func (*JobExecutor) DagExecute ¶ added in v2.1.0
func (e *JobExecutor) DagExecute() JobsError
func (*JobExecutor) Execute ¶
func (e *JobExecutor) Execute() JobsError
Effectively execute jobs and return collected errors as JobsError
func (*JobExecutor) GetDot ¶ added in v2.1.1
func (e *JobExecutor) GetDot() string
return a graphviz dot representation of the execution graph you can render it using graphviz or pasting output to https://dreampuf.github.io/GraphvizOnline/
func (*JobExecutor) IsAcyclic ¶ added in v2.1.0
func (e *JobExecutor) IsAcyclic() bool
Check that the jobs registered in the executor don't make a cyclic dependency (use Kahn's topological sort algorithm)
func (*JobExecutor) Len ¶
func (e *JobExecutor) Len() int
Return the total number of jobs added to the jobExecutor
func (*JobExecutor) OnJobDone ¶
func (e *JobExecutor) OnJobDone(fn jobEventHandler) *JobExecutor
Add a handler which will be called after a job is terminated
func (*JobExecutor) OnJobStart ¶
func (e *JobExecutor) OnJobStart(fn jobEventHandler) *JobExecutor
Add a handler which will be called before a job is started
func (*JobExecutor) OnJobsDone ¶
func (e *JobExecutor) OnJobsDone(fn jobsEventHandler) *JobExecutor
Add a handler which will be called after all jobs are terminated
func (*JobExecutor) OnJobsStart ¶
func (e *JobExecutor) OnJobsStart(fn jobsEventHandler) *JobExecutor
Add a handler which will be called before any jobs is started
func (*JobExecutor) WithFifoOutput ¶
func (e *JobExecutor) WithFifoOutput() *JobExecutor
Display full jobStatus as they arrive
func (*JobExecutor) WithInterleavedOutput ¶ added in v2.1.2
func (e *JobExecutor) WithInterleavedOutput() *JobExecutor
Print stdout and stderr of command directly to stdout as they arrive prefixing the ouput with the job name It overrides cmd.Stdin and cmd.Stdout so it won't work well with other With*Output methods that rely on collecting them to display them later (typically WithOrderedOutput will have nothing to display)
func (*JobExecutor) WithOngoingStatusOutput ¶
func (e *JobExecutor) WithOngoingStatusOutput() *JobExecutor
Display a job status report updated each time a job start or end be carefull when dealing with other handler that generate output as it will potentially break progress output
func (*JobExecutor) WithOrderedOutput ¶
func (e *JobExecutor) WithOrderedOutput() *JobExecutor
Display doneReport when all jobs are Done
func (*JobExecutor) WithProgressBarOutput ¶
func (e *JobExecutor) WithProgressBarOutput(length int, keepOnDone bool, colorEscSeq string) *JobExecutor
- length is the number of characters used to print the progress bar - keepOnDone determines if the progress bar should be kept on the screen when done or not - colorEscSeq is an ANSII terminal escape sequence ie: "\033[32m"
func (*JobExecutor) WithStartOutput ¶
func (e *JobExecutor) WithStartOutput() *JobExecutor
Output a line to say a job is starting
func (*JobExecutor) WithStartSummary ¶
func (e *JobExecutor) WithStartSummary() *JobExecutor
Output a summary of jobs that will be run