Documentation ¶
Index ¶
- Variables
- func RunCmd(dir, name string, arg ...string) (out string, err error)
- type Cmd
- func (c *Cmd) AddEnv(name, value string) *Cmd
- func (c *Cmd) Cancel()
- func (c *Cmd) Error() string
- func (c *Cmd) GetCmd() string
- func (c *Cmd) GetMsg() []byte
- func (c *Cmd) Output() string
- func (c *Cmd) Read() bool
- func (c *Cmd) Run() (string, error)
- func (c *Cmd) SetEnv(Env []string) *Cmd
- func (c *Cmd) SetEventHandler(eh *EventHandler) *Cmd
- func (c *Cmd) SetTimeout(dur time.Duration) *Cmd
- func (c *Cmd) Start() error
- func (c *Cmd) Wait() error
- type CmdEvent
- type Cron
- type EventHandler
- type HandleFunc
- type Job
- func (j *Job) Every(v ...int) uint32
- func (j *Job) EveryDay() uint32
- func (j *Job) EveryHour() uint32
- func (j *Job) EveryMinute() uint32
- func (j *Job) EveryMonth() uint32
- func (j *Job) EverySecond() uint32
- func (j *Job) EveryWeek() uint32
- func (j *Job) EveryWeekDay(weekday int, n ...int) uint32
- func (j *Job) EveryYear() uint32
- func (j *Job) RemoveTrigger(id uint32)
- func (j *Job) Restart()
- func (j *Job) Stop()
- type PipeCmd
- type Pipeline
- func (pipe *Pipeline) AddEnv(name, value string) *Pipeline
- func (pipe *Pipeline) Cancel()
- func (pipe *Pipeline) Do(name string, arg ...string) *PipeCmd
- func (pipe *Pipeline) Finished() bool
- func (pipe *Pipeline) GetCmdsOutput() (string, error)
- func (pipe *Pipeline) RemoveEnv(name string) *Pipeline
- func (pipe *Pipeline) Run() error
- func (pipe *Pipeline) SetCmdEventHandler(eh *EventHandler) *Pipeline
- func (pipe *Pipeline) SetEnv(keyValue string, more ...string) *Pipeline
- func (pipe *Pipeline) SetPipelineEventHandler(eh *EventHandler) *Pipeline
- func (pipe *Pipeline) SetTimeout(dur time.Duration) *Pipeline
- func (pipe *Pipeline) Start() error
- func (pipe *Pipeline) Under(dir string) *Pipeline
- func (pipe *Pipeline) Wait() error
- type PipelineEvent
Constants ¶
This section is empty.
Variables ¶
var DefaultEventHandler = &EventHandler{}
DefaultEventHandler default event handler
Functions ¶
Types ¶
type Cmd ¶
type Cmd struct { // run at dir Dir string // target executable name Name string // arguments of cmd Args []string // exec started Started bool // exec canceled Canceled bool // exec timedout TimedOut bool // exec failed by error Failed bool // exec done Done bool // exec timeout Timeout time.Duration // exec duration Duration time.Duration // EventHandler pointer EventHandler *EventHandler // native exec.Cmd target Cmd *exec.Cmd // contains filtered or unexported fields }
Cmd ...
func (*Cmd) SetEventHandler ¶
func (c *Cmd) SetEventHandler(eh *EventHandler) *Cmd
SetEventHandler set event handler
type Cron ¶
type Cron struct { Stopped bool // contains filtered or unexported fields }
Cron cron job scheduler
type EventHandler ¶
type EventHandler struct { // trigger when cmd successfully started CmdStarted CmdEvent // trigger when cmd get any output ( error will trigger CmdFailed ) CmdRead CmdEvent // trigger when cmd be canceled CmdCanceled CmdEvent // trigger when cmd failed which means process throw error CmdFailed CmdEvent // trigger when cmd done without any error CmdDone CmdEvent // trigger when pipeline successfully started PipelineStarted PipelineEvent // trigger when pipeline be canceled PipelineCanceled PipelineEvent // trigger when pipeline failed PipelineFailed PipelineEvent // trigger when pipeline done without any error PipelineDone PipelineEvent }
EventHandler bind event hanlder to do logging or other handling as you want be careful that all event handler function will be triggered synchronously to provide you synchronously control. use `go func()` inside handler for asynchronously control
type HandleFunc ¶
HandleFunc handler after execution of Cmd
type Job ¶
Job cron job instance
func (*Job) Every ¶
Every set specific time in [second(0~59), minute(0~59), hour(0~23), day(1~31), month(1~12)], unset part will be pretended as every (*). Invalid value will be set to first valid value. Return trigger id.
func (*Job) EveryMinute ¶
EveryMinute setup trigger which run job every minute (**:**:00)
func (*Job) EveryMonth ¶
EveryMonth setup trigger which run job every month (1st 00:00:00)
func (*Job) EverySecond ¶
EverySecond setup trigger which run job every second (**:**:**)
func (*Job) EveryWeekDay ¶
EveryWeekDay setup trigger which run job every weekday at time. If time unset it will be 00:00:00.
func (*Job) RemoveTrigger ¶
RemoveTrigger remove trigger by id
type PipeCmd ¶
type PipeCmd struct { Cmd *Cmd HandleFunc HandleFunc HandleMsg string DelayDur time.Duration // contains filtered or unexported fields }
PipeCmd cmd in pipeline
func (*PipeCmd) Handle ¶
func (pcmd *PipeCmd) Handle(f HandleFunc) *PipeCmd
Handle set HandleFunc to cmd for handling final output or error.
func (*PipeCmd) SkipErr ¶
func (pcmd *PipeCmd) SkipErr(f HandleFunc) *PipeCmd
SkipErr add handler after cmd to skip err.
type Pipeline ¶
type Pipeline struct { // pipeline started Started bool // pipeline done Done bool // pipeline failed Failed bool // pipeline canceld Canceled bool // pipline Timedout Timedout bool // Cmd pointer slice PipeCmds []*PipeCmd // current index of PipeCmd CurrentIndex int // EventHandler EventHandler *EventHandler // TimeoutDur duration TimeoutDur time.Duration // FailureMsg custom error message when failed at handler FailureMsg string // contains filtered or unexported fields }
Pipeline commands pipeline
func (*Pipeline) GetCmdsOutput ¶
GetCmdsOutput get output of all Cmds concat into one string
func (*Pipeline) SetCmdEventHandler ¶
func (pipe *Pipeline) SetCmdEventHandler(eh *EventHandler) *Pipeline
SetCmdEventHandler set Event Handler for cmds. It inheirt from pipeline's by default.
func (*Pipeline) SetPipelineEventHandler ¶
func (pipe *Pipeline) SetPipelineEventHandler(eh *EventHandler) *Pipeline
SetPipelineEventHandler set event handler of pipeline
func (*Pipeline) SetTimeout ¶
SetTimeout set timeout
type PipelineEvent ¶
type PipelineEvent func(pipe *Pipeline)
PipelineEvent pipeline event handle func