Documentation ¶
Index ¶
Constants ¶
const ( // JobExecutionTimesKey 定义存储 Job 执行次数的 Key JobExecutionTimesKey = "job:times:%s" // JobExecutionTimesDateKey 定义存储 Job 执行次数的 Key JobExecutionTimesDateKey = "job:times:%s:%s" // JobExecutionTimesNodeKey 定义存储包含 Node 的 Job 执行次数的 Key JobExecutionTimesNodeKey = "job:times:node:%s:%s" // JobExecutionTimesNodeDateKey 定义存储包含 Node 的 Job 执行次数的 Key JobExecutionTimesNodeDateKey = "job:times:node:%s:%s:%s" // JobExecutionTimesSuccessField Job 执行次数�成功字段 JobExecutionTimesSuccessField = "success" // JobExecutionTimesFailedField Job 执行次数失败字段 JobExecutionTimesFailedField = "failed" )
const ( // ETCDFailedRetryInterval ETCD 失败重试间隔 ETCDFailedRetryInterval = 1 * time.Second )
Variables ¶
var ( // ExecutorDefaultTimeout 执行器默认超时 ExecutorDefaultTimeout = 1 * time.Hour )
Functions ¶
Types ¶
type Agent ¶
type Agent struct {
// contains filtered or unexported fields
}
Agent 获取 Job 配置,根据 Job 规则运行对应的 Job
type CronSchedule ¶
type CronSchedule struct {
Second, Minute, Hour, Dom, Month, Dow uint64
}
CronSchedule 为类似 Crontab 的计划配置的实现
type Executor ¶
type Executor interface { // 运行 Run(context.Context, time.Duration, []string) (string, bool) // 停止 Stop() }
Executor 执行器接口 Run(参数) (执行结果,执行是否成功) Stop()
type ExecutorShell ¶
type ExecutorShell struct {
// contains filtered or unexported fields
}
ExecutorShell Shell 执行器的具体实现
type Job ¶
type Job struct { *logic.AgentJobConfig // contains filtered or unexported fields }
Job 定义执行 Job 的结构
type JobManager ¶
JobManager 是 Job 的管理者 负责从 etcd 获取 Job 配置,启动相对应的 Job,与 Job 执行结果回调
var ( // JobsManager 具体的 JobManager 实例 JobsManager *JobManager )
func (*JobManager) AddJob ¶
func (jobManager *JobManager) AddJob(jobConf *logic.AgentJobConfig)
AddJob 新加 Job
func (*JobManager) DelJob ¶
func (jobManager *JobManager) DelJob(jobConf *logic.AgentJobConfig)
DelJob 删除 Job
func (*JobManager) UpdateJob ¶
func (jobManager *JobManager) UpdateJob(jobConf *logic.AgentJobConfig)
UpdateJob 更新 Job
type JobResultMySQLStorage ¶
type JobResultMySQLStorage struct {
// contains filtered or unexported fields
}
JobResultMySQLStorage 使用 MySQL 存储 Job 结果的对象
func NewJobResultMySQLStorage ¶
func NewJobResultMySQLStorage(ctx context.Context, host, user, pass, dbname string) (*JobResultMySQLStorage, error)
JobResultMySQLStorage ��Job 执行日志 MySQL 存储
func (*JobResultMySQLStorage) Put ¶
func (s *JobResultMySQLStorage) Put(data *logic.AgentExecutionResult)
Put 将日志丢到队列
func (*JobResultMySQLStorage) Serve ¶
func (s *JobResultMySQLStorage) Serve(ctx context.Context)
Serve 启动定期同步数据库服务
type JobResultStorage ¶
type JobResultStorage interface {
Put(*logic.AgentExecutionResult)
}
JobResultStorage 存储 Job 结果的 Storage 接口
type JobResultTimesRedisStorage ¶
type JobResultTimesRedisStorage struct {
// contains filtered or unexported fields
}
JobResultTimesRedisStorage 使用 Redis 存储 Job 执行次数的对象
func NewJobResultTimesRedisStorage ¶
func NewJobResultTimesRedisStorage(address, auth string, maxConnNum int, idleTimeout time.Duration) (*JobResultTimesRedisStorage, error)
NewJobResultTimesRedisStorage 新建一个存储 Job 执行次数的 Redis 存储
func (*JobResultTimesRedisStorage) Put ¶
func (s *JobResultTimesRedisStorage) Put(data *logic.AgentExecutionResult)
Put 存储数据到存储
type ParseOption ¶
type ParseOption int
ParseOption Configuration options for creating a parser. Most options specify which fields should be included, while others enable features. If a field is not included the parser will assume a default value. These options do not change the order fields are parse in.
const ( // Second Seconds field, default 0 Second ParseOption = 1 << iota // Minute Minutes field, default 0 Minute // Hour Hours field, default 0 Hour // Dom Day of month field, default * Dom // Month field, default * Month // Dow Day of week field, default * Dow // DowOptional Optional day of week field, default * DowOptional // Descriptor Allow descriptors such as @monthly, @weekly, etc. Descriptor )
type Parser ¶
type Parser struct {
// contains filtered or unexported fields
}
Parser A custom Parser that can be configured.
func NewParser ¶
func NewParser(options ParseOption) Parser
NewParser Creates a custom Parser with custom options.
// Standard parser without descriptors specParser := NewParser(Minute | Hour | Dom | Month | Dow) sched, err := specParser.Parse("0 0 15 */3 *") // Same as above, just excludes time fields subsParser := NewParser(Dom | Month | Dow) sched, err := specParser.Parse("15 */3 *") // Same as above, just makes Dow optional subsParser := NewParser(Dom | Month | DowOptional) sched, err := specParser.Parse("15 */3")
type Schedule ¶
Schedule 定义计划生成器
func Parse ¶
Parse returns a new crontab schedule representing the given spec. It returns a descriptive error if the spec is not valid.
It accepts
- Full crontab specs, e.g. "* * * * * ?"
- Descriptors, e.g. "@midnight", "@every 1h30m"
func ParseStandard ¶
ParseStandard returns a new crontab schedule representing the given standardSpec (https://en.wikipedia.org/wiki/Cron). It differs from Parse requiring to always pass 5 entries representing: minute, hour, day of month, month and day of week, in that order. It returns a descriptive error if the spec is not valid.
It accepts
- Standard crontab specs, e.g. "* * * * ?"
- Descriptors, e.g. "@midnight", "@every 1h30m"