Documentation
¶
Index ¶
- Constants
- func GetCurrentDirectory() string
- func GetIDFromKey(key string) string
- func NewEtcdTimeoutContext(w *worker) (context.Context, context.CancelFunc)
- func NewLogger() (*zap.Logger, error)
- func NewWorker(conf *Config) (w *worker)
- type Cmd
- type Config
- type Cron
- func (c *Cron) AddFunc(spec string, cmd func() error) (EntryID, error)
- func (c *Cron) AddJob(spec string, cmd NamedJob) (EntryID, error)
- func (w Cron) GetJobContentFromKv(key []byte, value []byte) (*Job, error)
- func (w Cron) GetOnceJobFromKv(key []byte, value []byte) (*OnceJob, error)
- func (w Cron) KillExecutingProc(process *Process)
- func (c *Cron) Remove(id EntryID)
- func (c *Cron) Run()
- func (c *Cron) Schedule(schedule Schedule, job NamedJob) EntryID
- func (c *Cron) Stop() error
- type CronJob
- type CronTaskStatus
- type EntryID
- type FuncJob
- type Job
- func (j *Job) Cmds() (cmds map[string]*Cmd)
- func (w Job) GetJobContentFromKv(key []byte, value []byte) (*Job, error)
- func (w Job) GetOnceJobFromKv(key []byte, value []byte) (*OnceJob, error)
- func (w Job) KillExecutingProc(process *Process)
- func (j *Job) Lock() error
- func (j *Job) Run(taskOptions ...TaskOption) error
- func (j *Job) RunWithRecovery()
- func (j *Job) Unlock()
- func (j *Job) ValidRules() error
- type JobWrapper
- type Jobs
- type NamedJob
- type OnceJob
- type Process
- type ProcessVal
- type Schedule
- type Task
- type TaskOption
- type TaskResult
- type Timer
Constants ¶
View Source
const ( JobsKeyPrefix = "/juno/cronjob/job/" // job prefix OnceKeyPrefix = "/juno/cronjob/once/" // job that run immediately LockKeyPrefix = "/juno/cronjob/lock/" // job lock (only for single-node mode job) ProcKeyPrefix = "/juno/cronjob/proc/" // running process ResultKeyPrefix = "/juno/cronjob/result/" // task result (logs and status) )
View Source
const ( TypeNormal = 0 // 运行各节点都能运行任务 TypeAlone = 1 // 同一时间只允许一个节点一个任务运行 )
Variables ¶
This section is empty.
Functions ¶
func GetCurrentDirectory ¶
func GetCurrentDirectory() string
func NewEtcdTimeoutContext ¶
func NewEtcdTimeoutContext(w *worker) (context.Context, context.CancelFunc)
NewEtcdTimeoutContext return a new etcdTimeoutContext
Types ¶
type Cmd ¶
func (Cmd) GetJobContentFromKv ¶
func (Cmd) GetOnceJobFromKv ¶
func (Cmd) KillExecutingProc ¶
func (w Cmd) KillExecutingProc(process *Process)
type Config ¶
type Config struct {
EtcdConfigKey string // jupiter.etcdv3.xxxxxx
ReqTimeout int // 请求操作ETCD的超时时间,单位秒
RequireLockTime int64 // 抢锁等待时间,单位秒
HostName string
AppIP string
// contains filtered or unexported fields
}
type Cron ¶
Cron ...
func (Cron) GetJobContentFromKv ¶
func (Cron) GetOnceJobFromKv ¶
func (Cron) KillExecutingProc ¶
func (w Cron) KillExecutingProc(process *Process)
type CronTaskStatus ¶
type CronTaskStatus string
var ( CronTaskStatusProcessing CronTaskStatus = "processing" CronTaskStatusSuccess CronTaskStatus = "success" CronTaskStatusFailed CronTaskStatus = "failed" CronTaskStatusTimeout CronTaskStatus = "timeout" )
type Job ¶
type Job struct {
ID string `json:"id"`
Name string `json:"name"`
Script string `json:"script"`
Timers []*Timer `json:"timers"`
Enable bool `json:"enable"` // 可手工控制的状态
Timeout int64 `json:"timeout"` // 单位时间秒,任务执行时间超时设置,大于 0 时有效
Env string `json:"env"`
Zone string `json:"zone"`
Nodes []string `json:"nodes"`
// 执行任务失败重试次数
// 默认为 0,不重试
RetryCount int `json:"retry_count"`
// 执行任务失败重试时间间隔
// 单位秒,如果不大于 0 则马上重试
RetryInterval int `json:"retry_interval"`
// 任务类型
// 0: 普通任务,各节点均可运行
// 1: 单机任务,同时只能单节点在线
JobType int `json:"job_type"`
// contains filtered or unexported fields
}
需要执行的 cron cmd 命令 注册到 /cronsun/cmd/<id>
func (Job) GetJobContentFromKv ¶
func (Job) GetOnceJobFromKv ¶
func (Job) KillExecutingProc ¶
func (w Job) KillExecutingProc(process *Process)
func (*Job) Run ¶
func (j *Job) Run(taskOptions ...TaskOption) error
func (*Job) RunWithRecovery ¶
func (j *Job) RunWithRecovery()
func (*Job) ValidRules ¶
type OnceJob ¶
单次任务
func (OnceJob) GetJobContentFromKv ¶
func (OnceJob) GetOnceJobFromKv ¶
func (OnceJob) KillExecutingProc ¶
func (w OnceJob) KillExecutingProc(process *Process)
func (*OnceJob) RunWithRecovery ¶
func (o *OnceJob) RunWithRecovery(taskOptions ...TaskOption)
type Process ¶
type Process struct {
// parse from key path
ID string `json:"id"` // pid
JobID string `json:"jobId"`
NodeID string `json:"nodeId"`
TaskID uint64 `json:"task_id"`
// parse from value
ProcessVal
// contains filtered or unexported fields
}
当前执行中的任务信息 key: /{etcd_prefix}/jobId/taskId/node/pid value: 开始执行时间 key 会自动过期,防止进程意外退出后没有清除相关 key,过期时间可配置
func GetProcFromKey ¶
type ProcessVal ¶
type Task ¶
type Task struct {
TaskID uint64
// contains filtered or unexported fields
}
func NewTask ¶
func NewTask(job *Job, ops ...TaskOption) *Task
type TaskOption ¶
type TaskOption func(t *Task)
func WithTaskID ¶
func WithTaskID(taskId uint64) TaskOption
type TaskResult ¶
Source Files
¶
Click to show internal directories.
Click to hide internal directories.