agent

package
v0.0.0-...-27e8298 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 3, 2020 License: MIT Imports: 19 Imported by: 0

Documentation

Index

Constants

View Source
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"
)
View Source
const (
	// ETCDFailedRetryInterval  ETCD 失败重试间隔
	ETCDFailedRetryInterval = 1 * time.Second
)

Variables

View Source
var (
	// ExecutorDefaultTimeout 执行器默认超时
	ExecutorDefaultTimeout = 1 * time.Hour
)

Functions

func Run

func Run(pctx context.Context)

Run 为 Agent 启动方法 将启动 Agent 与 Job Manager 开始工作

func Stop

func Stop()

Stop 降停止所有 Agent 服务

Types

type Agent

type Agent struct {
	// contains filtered or unexported fields
}

Agent 获取 Job 配置,根据 Job 规则运行对应的 Job

func NewAgent

func NewAgent(ctx context.Context) *Agent

NewAgent 新建一个 Agent 实例

func (*Agent) KeepAlive

func (agent *Agent) KeepAlive()

KeepAlive 定时发送心跳包和自身的 Tag 到 etcd

type CronSchedule

type CronSchedule struct {
	Second, Minute, Hour, Dom, Month, Dow uint64
}

CronSchedule 为类似 Crontab 的计划配置的实现

func (*CronSchedule) Next

func (s *CronSchedule) Next(t time.Time) time.Time

Next 返回下次执行时间

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 执行器的具体实现

func (*ExecutorShell) Run

func (executor *ExecutorShell) Run(pctx context.Context, timeout time.Duration, params []string) (string, bool)

Run 具体的执行实现

func (*ExecutorShell) Stop

func (executor *ExecutorShell) Stop()

Stop 停止执行器

type Job

type Job struct {
	*logic.AgentJobConfig
	// contains filtered or unexported fields
}

Job 定义执行 Job 的结构

func NewJob

func NewJob(pctx context.Context, conf *logic.AgentJobConfig, callback jobCallback) (*Job, error)

NewJob 新建一个 Job 实例

func (*Job) ScheduleRun

func (job *Job) ScheduleRun() error

ScheduleRun 根据计划执行 Job

func (*Job) Stop

func (job *Job) Stop()

Stop 停止 Job 计划执行

type JobManager

type JobManager struct {
	sync.RWMutex
	// contains filtered or unexported fields
}

JobManager 是 Job 的管理者 负责从 etcd 获取 Job 配置,启动相对应的 Job,与 Job 执行结果回调

var (

	// JobsManager 具体的 JobManager 实例
	JobsManager *JobManager
)

func NewJobManager

func NewJobManager(ctx context.Context) *JobManager

NewJobManager 新建一个 Job 管理者

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) Serve

func (jobManager *JobManager) Serve() error

Serve 用于发现 Jobs 修改

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

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

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")

func (Parser) Parse

func (p Parser) Parse(spec string) (Schedule, error)

Parse returns a new crontab schedule representing the given spec. It returns a descriptive error if the spec is not valid. It accepts crontab specs and features configured by NewParser.

type Schedule

type Schedule interface {
	Next(time.Time) time.Time
}

Schedule 定义计划生成器

func Parse

func Parse(spec string) (Schedule, error)

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

func ParseStandard(standardSpec string) (Schedule, error)

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"

type TickSchedule

type TickSchedule struct {
	Every time.Duration
}

TickSchedule 为每多久执行一次的计划配置的实现

func (*TickSchedule) Next

func (s *TickSchedule) Next(t time.Time) time.Time

Next 返回下次执行时间

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL