Documentation
¶
Index ¶
- Constants
- Variables
- func BanAccount(email string) error
- func CreateAccount(u *Account) error
- 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 EnsureAccountIndex() 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 ISNodeAlive(id string) (bool, error)
- func Init(baseConfFile string, watchConfiFile bool) (err error)
- func IsValidAsKeyPath(s string) bool
- func JobKey(group, id string) string
- func NewEtcdTimeoutContext(c *Client) (context.Context, context.CancelFunc)
- func NextID() string
- func PutCsctl(cmd *CsctlCmd) error
- func PutOnce(group, jobID, nodeID string) error
- func Reload(i interface{})
- func RemoveNode(query interface{}) error
- func StartNoticer(n Noticer)
- func StartProc() error
- func UpdateAccount(query bson.M, change bson.M) error
- func WatchCsctl() client.WatchChan
- func WatchGroups() client.WatchChan
- func WatchJobs() client.WatchChan
- func WatchNode() client.WatchChan
- func WatchOnce() client.WatchChan
- type Account
- 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) Revoke(id client.LeaseID) (*client.LeaseRevokeResponse, error)
- func (c *Client) Watch(key string, opts ...client.OpOption) client.WatchChan
- type Cmd
- type CsctlCmd
- 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) Init(nodeID, hostname, ip 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) 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 NodeCmd
- type Noticer
- type Process
- type Role
- type StatExecuted
- type UserStatus
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 (
Coll_Account = "account"
)
View Source
const (
Coll_Node = "node"
)
View Source
const (
DefaultJobGroup = "default"
)
View Source
const VersionNumber = "0.3.2"
Variables ¶
View Source
var ( InvalidNodeCmdErr = errors.New("invalid node command") NodeCmds = []string{ "unknown", "rmold", "sync", } )
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.") )
View Source
var (
Version = fmt.Sprintf("v%s (build %s)", VersionNumber, runtime.Version())
)
Functions ¶
func BanAccount ¶ added in v0.2.1
func CreateAccount ¶ added in v0.2.1
func DeleteGroupById ¶
func DeleteGroupById(id string) (*client.DeleteResponse, error)
func EnsureAccountIndex ¶ added in v0.2.1
func EnsureAccountIndex() error
func GetJobLatestLogListByJobIds ¶
func GetJobLatestLogListByJobIds(jobIds []string) (m map[string]*JobLatestLog, err error)
func ISNodeAlive ¶ added in v0.2.2
func IsValidAsKeyPath ¶
func NewEtcdTimeoutContext ¶ added in v0.3.1
func NewEtcdTimeoutContext(c *Client) (context.Context, context.CancelFunc)
NewEtcdTimeoutContext return a new etcdTimeoutContext
func PutOnce ¶
马上执行 job 任务 注册到 /cronsun/once/group/<jobID> value 若执行单个结点,则值为 NodeID 若 job 所在的结点都需执行,则值为空 ""
func RemoveNode ¶ added in v0.2.2
func RemoveNode(query interface{}) error
func StartNoticer ¶
func StartNoticer(n Noticer)
func WatchCsctl ¶ added in v0.3.2
func WatchGroups ¶
Types ¶
type Account ¶ added in v0.2.1
type Account struct {
ID bson.ObjectId `bson:"_id" json:"id"`
Role Role `bson:"role" json:"role"`
Email string `bson:"email" json:"email"`
Password string `bson:"password" json:"password"`
Salt string `bson:"salt" json:"salt"`
Status UserStatus `bson:"status" json:"status"`
Session string `bson:"session" json:"-"`
// If true, role and status are unchangeable, email and password can be change by it self only.
Unchangeable bool `bson:"unchangeable" json:"-"`
CreateTime time.Time `bson:"createTime" json:"createTime"`
}
func GetAccountByEmail ¶ added in v0.2.1
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 GetGroupFromKv ¶
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"`
// 单独对任务指定日志清除时间
LogExpiration int `json:"log_expiration"`
// 控制同时执行任务数
Count *int64 `json:"-"`
// contains filtered or unexported fields
}
需要执行的 cron cmd 命令 注册到 /cronsun/cmd/groupName/<id>
func GetJobFromKv ¶
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"` // 运行此次任务的节点 id,索引
Hostname string `bson:"hostname" json:"hostname"` // 运行此次任务的节点主机名称,索引
IP string `bson:"ip" json:"ip"` // 运行此次任务的节点主机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"` // 任务执行完毕时间,精确到毫秒
Cleanup time.Time `bson:"cleanup,omitempty" json:"-"` // 日志清除时间标志
}
任务执行记录
type JobRule ¶
type Node ¶
type Node struct {
ID string `bson:"_id" json:"id"` // machine id
PID string `bson:"pid" json:"pid"` // 进程 pid
PIDFile string `bson:"-" json:"-"`
IP string `bson:"ip" json:"ip"` // node ip
Hostname string `bson:"hostname" json:"hostname"`
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 ¶
func GetNodesByID ¶ added in v0.3.1
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"`
Date string `bson:"date" json:"date"`
}
func JobLogDailyStat ¶ added in v0.2.3
func JobLogDailyStat(begin, end time.Time) (ls []*StatExecuted, err error)
func JobLogStat ¶
func JobLogStat() (s *StatExecuted, err error)
type UserStatus ¶ added in v0.2.1
type UserStatus int
const ( UserBanned UserStatus = -1 UserActived UserStatus = 1 )
func (UserStatus) Defined ¶ added in v0.2.1
func (s UserStatus) Defined() bool
Source Files
¶
Directories
¶
| Path | Synopsis |
|---|---|
|
bin
|
|
|
csctl
command
|
|
|
node
command
node 服务 用于在所需要执行 cron 任务的机器启动服务,替代 cron 执行所需的任务
|
node 服务 用于在所需要执行 cron 任务的机器启动服务,替代 cron 执行所需的任务 |
|
web
command
|
|
|
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.




