Documentation ¶
Index ¶
- Constants
- func GetCurrentDirectory() string
- func GetIDFromKey(key string) string
- func NewEtcdTimeoutContext(w *Worker) (context.Context, context.CancelFunc)
- type Cmd
- type Config
- type Cron
- type CronJob
- type CronTaskStatus
- type EntryID
- type FuncJob
- type Job
- type JobWrapper
- type Jobs
- type NamedJob
- type OnceJob
- type Process
- type ProcessVal
- type Schedule
- type Task
- type TaskOption
- type TaskResult
- type Timer
- type Worker
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 Config ¶
type Config struct { Enable bool EtcdConfigKey string // jupiter.etcdv3.xxxxxx ReqTimeout int // 请求操作ETCD的超时时间,单位秒 RequireLockTime int64 // 抢锁等待时间,单位秒 HostName string AppIP string // contains filtered or unexported fields }
type Cron ¶
type Cron struct { *Worker *cron.Cron // contains filtered or unexported fields }
Cron ...
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"` // 用于访问etcd *Worker `json:"-"` // contains filtered or unexported fields }
需要执行的 cron cmd 命令 注册到 /cronsun/cmd/<id>
func (*Job) Run ¶
func (j *Job) Run(taskOptions ...TaskOption) error
func (*Job) RunWithRecovery ¶
func (j *Job) RunWithRecovery()
func (*Job) ValidRules ¶
type OnceJob ¶
单次任务
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 ¶
type Worker ¶ added in v0.1.2
type Worker struct { *Config *etcdv3.Client *Cron ID string ImmediatelyRun bool // 是否立即执行 // contains filtered or unexported fields }
Node 执行 cron 命令服务的结构体
func (*Worker) GetJobContentFromKv ¶ added in v0.1.2
func (*Worker) GetOnceJobFromKv ¶ added in v0.1.2
func (*Worker) KillExecutingProc ¶ added in v0.1.2
Source Files ¶
Click to show internal directories.
Click to hide internal directories.