Documentation
¶
Index ¶
- Constants
- Variables
- func CalcDaily(schedule *models.Schedule, seed time.Time) (time.Time, error)
- func CalcInterval(schedule *models.Schedule, seed time.Time) (time.Time, error)
- func CalcMonthly(schedule *models.Schedule, seed time.Time) (time.Time, error)
- func CalcSchedule(schedule *models.Schedule, seed time.Time) (time.Time, error)
- func CalcWeekly(schedule *models.Schedule, seed time.Time) (time.Time, error)
- type CoreHandler
- type CoreHandlerFunc
- type Driver
- func (driver *Driver) Action(jobid string, action string)
- func (driver *Driver) Clear()
- func (driver *Driver) Dispatch()
- func (driver *Driver) ExecuteHandleFunc(state int, context *DriverContext)
- func (driver *Driver) NewExecuteContext(job *Job, core *ExecCore, nextat time.Time, err error) *DriverContext
- func (driver *Driver) NewSelectContext(job *Job, nextat time.Time) *DriverContext
- func (driver *Driver) NewStopedContext(job *Job, execat time.Time, nextat time.Time, err error) *DriverContext
- func (driver *Driver) OnCoreHandlerFunc(core *ExecCore, state int, err error)
- func (driver *Driver) Remove(jobid string)
- func (driver *Driver) SelectHandleFunc(context *DriverContext)
- func (driver *Driver) Set(jobbase *models.JobBase)
- func (driver *Driver) StopedHandleFunc(state int, context *DriverContext)
- type DriverContext
- type DriverExecuteHandlerFunc
- type DriverSelectHandlerFunc
- type DriverStopedHandlerFunc
- type ExecCore
- type ExecDriver
- type ExitState
- type ICoreHandler
- type IDriverHandler
- type IExecDriver
- type Job
- type JobState
- type StdOutput
Constants ¶
View Source
const ZERO_TICK float64 = 0.0000000
Variables ¶
View Source
var ( ErrScheduleInvalid = errors.New("schedule invalid.") //任务计划无效 ErrScheduleExpired = errors.New("schedule expired.") //任务计划过期 )
View Source
var ( //执行超时(超过job.ExecMaxSec阀值) ErrExecuteDeadline = errors.New("the job has been executed for too long and has exceeded the timeout threshold.") //执行异常 ErrExecuteException = errors.New("job execute exception") //执行终止 ErrExecuteTerminal = errors.New("job execute terminal error") )
执行错误定义
Functions ¶
Types ¶
type CoreHandler ¶
type CoreHandler struct {
ICoreHandler
}
type CoreHandlerFunc ¶
func (CoreHandlerFunc) OnCoreHandlerFunc ¶
func (fn CoreHandlerFunc) OnCoreHandlerFunc(core *ExecCore, state int, err error)
type Driver ¶
type Driver struct { sync.RWMutex CoreHandler Root string // contains filtered or unexported fields }
Driver is exported
func (*Driver) ExecuteHandleFunc ¶
func (driver *Driver) ExecuteHandleFunc(state int, context *DriverContext)
func (*Driver) NewExecuteContext ¶
func (driver *Driver) NewExecuteContext(job *Job, core *ExecCore, nextat time.Time, err error) *DriverContext
NewExecuteContext构造
func (*Driver) NewSelectContext ¶
func (driver *Driver) NewSelectContext(job *Job, nextat time.Time) *DriverContext
NewSelectContext构造
func (*Driver) NewStopedContext ¶
func (driver *Driver) NewStopedContext(job *Job, execat time.Time, nextat time.Time, err error) *DriverContext
NewStopedContext构造
func (*Driver) OnCoreHandlerFunc ¶
func (*Driver) SelectHandleFunc ¶
func (driver *Driver) SelectHandleFunc(context *DriverContext)
func (*Driver) StopedHandleFunc ¶
func (driver *Driver) StopedHandleFunc(state int, context *DriverContext)
type DriverContext ¶
type DriverContext struct { Job *Job StdOut string ErrOut string ExecErr string ExecAt time.Time NextAt time.Time ExecTimes float64 }
DriverContext上下文定义
type DriverExecuteHandlerFunc ¶
type DriverExecuteHandlerFunc func(state int, context *DriverContext)
func (DriverExecuteHandlerFunc) OnDriverExecuteHandlerFunc ¶
func (fn DriverExecuteHandlerFunc) OnDriverExecuteHandlerFunc(state int, context *DriverContext)
type DriverSelectHandlerFunc ¶
type DriverSelectHandlerFunc func(context *DriverContext)
func (DriverSelectHandlerFunc) OnDriverSelectHandlerFunc ¶
func (fn DriverSelectHandlerFunc) OnDriverSelectHandlerFunc(context *DriverContext)
type DriverStopedHandlerFunc ¶
type DriverStopedHandlerFunc func(state int, context *DriverContext)
func (DriverStopedHandlerFunc) OnDriverStopedHandlerFunc ¶
func (fn DriverStopedHandlerFunc) OnDriverStopedHandlerFunc(state int, context *DriverContext)
type ExecCore ¶
type ExecCore struct { JobId string //任务编号 WorkDir string //工作目录 Exit ExitState //退出状态 ExecAt time.Time //本次执行时间 NextAt time.Time //下次执行时间 Schedule *models.Schedule //执行计划 ExecDriver *ExecDriver //执行驱动 // contains filtered or unexported fields }
func NewExecCore ¶
func NewExecCore(jobid string, schedule *models.Schedule, handler ICoreHandler) *ExecCore
func (*ExecCore) GetExecDriverPipeBuffer ¶
func (*ExecCore) GetExecTimes ¶
type ExecDriver ¶
type ExecDriver struct { Running bool //执行状态 Command *exec.Cmd //执行对象 ExecTimes float64 //总执行时长 StdOut StdOutput //标准输出 ErrOut StdOutput //错误输出 }
ExecDriver 任务执行体 负责任务执行的生命期和状态.
func NewExecDriver ¶
func NewExecDriver(name string, cmd string, env []string) (*ExecDriver, error)
func (*ExecDriver) ReadCommandPipeBuffer ¶
func (driver *ExecDriver) ReadCommandPipeBuffer(stdoutCh chan<- []byte, erroutCh chan<- []byte)
ReadCommandPipeBuffer 读取任务输出管道数据 StdOut.Buffer:标准输出 ErrOut.Buffer:错误输出 分别开启携程读取管道数据,避免读取阻塞. 若不开启携程,有种情况会出现读取stderr数据导致stdout读取阻塞.
func (*ExecDriver) SetCommandPipe ¶
func (driver *ExecDriver) SetCommandPipe() error
SetCommandPipe 设置command对象管道 指定程序标准输出到StdOut.reader & ErrOut.reader 设置失败返回error.
func (*ExecDriver) Start ¶
func (driver *ExecDriver) Start(start chan<- bool) error
func (*ExecDriver) Stop ¶
func (driver *ExecDriver) Stop() error
type ICoreHandler ¶
type IDriverHandler ¶
type IDriverHandler interface { //DriverContext Code = ERR_SCHEDULE_EXECUTE OnDriverExecuteHandlerFunc(state int, context *DriverContext) //DriverContext Code = ERR_SCHEDULE_INVALID OnDriverSelectHandlerFunc(context *DriverContext) //DriverContext Code = ERR_SCHEDULE_STOPED OnDriverStopedHandlerFunc(state int, context *DriverContext) }
Driver回调handler定义
type IExecDriver ¶
type IExecDriver interface { //启动任务 Start(start chan<- bool) error //停止任务 Stop() error //设置exec.cmd输入输出管道 SetCommandPipe() error //读取exec.cmd管道数据 ReadCommandPipeBuffer(stdoutCh chan<- []byte, erroutCh chan<- []byte) }
ExecDriver 接口定义
type Job ¶
type Job struct { JobId string //任务编号 Name string //任务名称 Root string //工作根目录 FileCode string //文件编码 WorkDir string //工作目录 Cmd string //执行命令 Env []string //环境变量 Timeout int //执行超时(秒) ExecMaxSec int64 //执行最长时长(时间戳:UNIX时间戳) State JobState //执行状态 LastExecAt time.Time //最后一次执行时间 LastError error //最后一次错误信息 // contains filtered or unexported fields }
func (*Job) CheckWithTimeout ¶
type StdOutput ¶
type StdOutput struct { Reader io.ReadCloser //输出读取对象(stdout或stderr) Buffer []byte //输出数据 }
StdOutput 输出数据结构定义
Click to show internal directories.
Click to hide internal directories.