Documentation
¶
Index ¶
- Constants
- Variables
- func CreateJobLog(j *Job, t time.Time, rs string, success bool)
- func DeleteGroupById(id string) (*client.DeleteResponse, error)
- func DeleteJob(group, id string) (resp *client.DeleteResponse, err error)
- func Exit(i interface{})
- func GetDb() *db.Mdb
- func GetGroups(nid string) (groups map[string]*Group, err error)
- func GetIDFromKey(key string) string
- func GetJobLatestLogListByJobIds(jobIds []string) (m map[string]*JobLatestLog, err error)
- func GetJobs() (jobs map[string]*Job, err error)
- func GroupKey(id string) string
- func ISNodeFault(id string) (bool, error)
- func Init() (err error)
- func IsValidAsKeyPath(s string) bool
- func JobKey(group, id string) string
- func NextID() string
- func PutOnce(group, jobID, nodeID string) error
- func Reload(i interface{})
- func StartNoticer(n Noticer)
- func StartProc() error
- func WatchGroups() client.WatchChan
- func WatchJobs() client.WatchChan
- func WatchNode() client.WatchChan
- func WatchOnce() client.WatchChan
- type Client
- func (c *Client) DelLock(key string) error
- func (c *Client) Delete(key string, opts ...client.OpOption) (*client.DeleteResponse, error)
- func (c *Client) Get(key string, opts ...client.OpOption) (*client.GetResponse, error)
- func (c *Client) GetLock(key string, id client.LeaseID) (bool, error)
- func (c *Client) Grant(ttl int64) (*client.LeaseGrantResponse, error)
- func (c *Client) KeepAliveOnce(id client.LeaseID) (*client.LeaseKeepAliveResponse, error)
- func (c *Client) Put(key, val string, opts ...client.OpOption) (*client.PutResponse, error)
- func (c *Client) PutWithModRev(key, val string, rev int64) (*client.PutResponse, error)
- func (c *Client) Watch(key string, opts ...client.OpOption) client.WatchChan
- type Cmd
- type Group
- type HttpAPI
- type Job
- func (j *Job) Avg(t, et time.Time)
- func (j *Job) Check() error
- func (j *Job) Cmds(nid string, gs map[string]*Group) (cmds map[string]*Cmd)
- func (j *Job) CountRunning() (int64, error)
- func (j *Job) Fail(t time.Time, msg string)
- func (j Job) IsRunOn(nid string, gs map[string]*Group) bool
- func (j *Job) Key() string
- func (j *Job) Notify(t time.Time, msg string)
- func (j *Job) Run() bool
- func (j *Job) RunOn(n string)
- func (j *Job) RunWithRecovery()
- func (j *Job) ShortName() string
- func (j *Job) String() string
- func (j *Job) Success(t time.Time, out string)
- func (j *Job) Valid() error
- func (j *Job) ValidRules() error
- type JobLatestLog
- type JobLog
- type JobRule
- type Mail
- type Message
- type Node
- type Noticer
- type Process
- type StatExecuted
Constants ¶
View Source
const ( KindCommon = iota KindAlone // 任何时间段只允许单机执行 KindInterval // 一个任务执行间隔内允许执行一次 )
View Source
const ( Coll_JobLog = "job_log" Coll_JobLatestLog = "job_latest_log" Coll_Stat = "stat" )
View Source
const Binary = "v0.1.1"
View Source
const (
Coll_Node = "node"
)
View Source
const (
DefaultJobGroup = "default"
)
Variables ¶
View Source
var ( ErrNotFound = errors.New("Record not found.") ErrValueMayChanged = errors.New("The value has been changed by others on this time.") ErrEmptyJobName = errors.New("Name of job is empty.") ErrEmptyJobCommand = errors.New("Command of job is empty.") ErrIllegalJobId = errors.New("Invalid id that includes illegal characters such as '/'.") ErrIllegalJobGroupName = errors.New("Invalid job group name that includes illegal characters such as '/'.") ErrEmptyNodeGroupName = errors.New("Name of node group is empty.") ErrIllegalNodeGroupId = errors.New("Invalid node group id that includes illegal characters such as '/'.") ErrSecurityInvalidCmd = errors.New("Security error: the suffix of script file is not on the whitelist.") ErrSecurityInvalidUser = errors.New("Security error: the user is not on the whitelist.") ErrNilRule = errors.New("invalid job rule, empty timer.") )
Functions ¶
func DeleteGroupById ¶
func DeleteGroupById(id string) (*client.DeleteResponse, error)
func GetJobLatestLogListByJobIds ¶
func GetJobLatestLogListByJobIds(jobIds []string) (m map[string]*JobLatestLog, err error)
func ISNodeFault ¶
func IsValidAsKeyPath ¶
func PutOnce ¶
马上执行 job 任务 注册到 /cronsun/once/group/<jobID> value 若执行单个结点,则值为 NodeID 若 job 所在的结点都需执行,则值为空 ""
func StartNoticer ¶
func StartNoticer(n Noticer)
func WatchGroups ¶
Types ¶
type Client ¶
var (
DefalutClient *Client
)
func (*Client) KeepAliveOnce ¶
func (*Client) PutWithModRev ¶
type Group ¶
type Group struct { ID string `json:"id"` Name string `json:"name"` NodeIDs []string `json:"nids"` }
结点类型分组 注册到 /cronsun/group/<id>
func GetGroupById ¶
func GetNodeGroups ¶
type Job ¶
type Job struct { ID string `json:"id"` Name string `json:"name"` Group string `json:"group"` Command string `json:"cmd"` User string `json:"user"` Rules []*JobRule `json:"rules"` Pause bool `json:"pause"` // 可手工控制的状态 Timeout int64 `json:"timeout"` // 任务执行时间超时设置,大于 0 时有效 // 设置任务在单个节点上可以同时允许多少个 // 针对两次任务执行间隔比任务执行时间要长的任务启用 Parallels int64 `json:"parallels"` // 执行任务失败重试次数 // 默认为 0,不重试 Retry int `json:"retry"` // 执行任务失败重试时间间隔 // 单位秒,如果不大于 0 则马上重试 Interval int `json:"interval"` // 任务类型 // 0: 普通任务 // 1: 单机任务 // 如果为单机任务,node 加载任务的时候 Parallels 设置 1 Kind int `json:"kind"` // 平均执行时间,单位 ms AvgTime int64 `json:"avg_time"` // 执行失败发送通知 FailNotify bool `json:"fail_notify"` // 发送通知地址 To []string `json:"to"` // contains filtered or unexported fields }
需要执行的 cron cmd 命令 注册到 /cronsun/cmd/groupName/<id>
func (*Job) RunWithRecovery ¶
func (j *Job) RunWithRecovery()
func (*Job) ValidRules ¶
type JobLatestLog ¶
type JobLatestLog struct { JobLog `bson:",inline"` RefLogId string `bson:"refLogId,omitempty" json:"refLogId"` }
func GetJobLatestLogList ¶
type JobLog ¶
type JobLog struct { Id bson.ObjectId `bson:"_id,omitempty" json:"id"` JobId string `bson:"jobId" json:"jobId"` // 任务 Id,索引 JobGroup string `bson:"jobGroup" json:"jobGroup"` // 任务分组,配合 Id 跳转用 User string `bson:"user" json:"user"` // 执行此次任务的用户 Name string `bson:"name" json:"name"` // 任务名称 Node string `bson:"node" json:"node"` // 运行此次任务的节点 ip,索引 Command string `bson:"command" json:"command,omitempty"` // 执行的命令,包括参数 Output string `bson:"output" json:"output,omitempty"` // 任务输出的所有内容 Success bool `bson:"success" json:"success"` // 是否执行成功 BeginTime time.Time `bson:"beginTime" json:"beginTime"` // 任务开始执行时间,精确到毫秒,索引 EndTime time.Time `bson:"endTime" json:"endTime"` // 任务执行完毕时间,精确到毫秒 }
任务执行记录
type JobRule ¶
type Node ¶
type Node struct { ID string `bson:"_id" json:"id"` // ip PID string `bson:"pid" json:"pid"` // 进程 pid Version string `bson:"version" json:"version"` UpTime time.Time `bson:"up" json:"up"` // 启动时间 DownTime time.Time `bson:"down" json:"down"` // 上次关闭时间 Alived bool `bson:"alived" json:"alived"` // 是否可用 Connected bool `bson:"-" json:"connected"` // 当 Alived 为 true 时有效,表示心跳是否正常 }
执行 cron cmd 的进程 注册到 /cronsun/node/<id>
func GetNodesBy ¶
type Process ¶
type Process struct { ID string `json:"id"` // pid JobID string `json:"jobId"` Group string `json:"group"` NodeID string `json:"nodeId"` Time time.Time `json:"time"` // 开始执行时间 // contains filtered or unexported fields }
当前执行中的任务信息 key: /cronsun/proc/node/group/jobId/pid value: 开始执行时间 key 会自动过期,防止进程意外退出后没有清除相关 key,过期时间可配置
func GetProcFromKey ¶
type StatExecuted ¶
type StatExecuted struct { Total int64 `bson:"total" json:"total"` Successed int64 `bson:"successed" json:"successed"` Failed int64 `bson:"failed" json:"failed"` }
func JobLogDayStat ¶
func JobLogDayStat(day time.Time) (s *StatExecuted, err error)
func JobLogStat ¶
func JobLogStat() (s *StatExecuted, err error)
Source Files
¶
Directories
¶
Path | Synopsis |
---|---|
bin
|
|
node
node 服务 用于在所需要执行 cron 任务的机器启动服务,替代 cron 执行所需的任务
|
node 服务 用于在所需要执行 cron 任务的机器启动服务,替代 cron 执行所需的任务 |
cron
This library implements a cron spec parser and runner.
|
This library implements a cron spec parser and runner. |
加载json(可配置扩展字段)配置文件 { "Debug": true, "Log": "@extend:./log.json" }
|
加载json(可配置扩展字段)配置文件 { "Debug": true, "Log": "@extend:./log.json" } |
Click to show internal directories.
Click to hide internal directories.