drive

package
v0.0.0-...-ca42a2b Latest Latest
Warning

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

Go to latest
Published: Jul 23, 2019 License: Apache-2.0 Imports: 23 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func InitExecutor

func InitExecutor()

func InitScheduler

func InitScheduler()

初始化

func InitTaskLogSink

func InitTaskLogSink()

初始化

func InitTaskManager

func InitTaskManager()

Types

type Executor

type Executor struct {
}

任务执行

var G_executor *Executor

func (*Executor) ExecTask

func (executor *Executor) ExecTask(task_info *TaskExecuteInfo)

执行任务

type Scheduler

type Scheduler struct {
	TaskTable     map[string]*TaskSchedulePlan // 任务调度表,key为Id+_+name
	TaskExecTable map[string]*TaskExecuteInfo  // 任务执行表
	TaskStopChan  chan *Task                   // 任务停止队列
	TaskDelChan   chan *Task                   // 任务删除队列
	TaskKillChan  chan *Task                   // 任务强杀队列
	//TaskExecManualChan chan *Task                   // 任务手动执队列
	TaskResultChan chan *TaskExecuteResult // 任务结果队列

}

任务调度

var G_scheduler *Scheduler

func (*Scheduler) AssTaskKey

func (scheduler *Scheduler) AssTaskKey(task *Task) string

组装任务key

func (*Scheduler) PushTaskResult

func (scheduler *Scheduler) PushTaskResult(task_result *TaskExecuteResult)

任务执行结果写入到结果队列中

type Task

type Task struct {
	Id                int64      `json:"id"`
	Name              string     `json:"name"`
	CreateTime        time.Time  `json:"create_time"`
	StartTime         time.Time  `json:"start_time"`
	ConsumeTime       float64    `json:"consume_time"`
	Overtime          int        `json:"overtime"`
	LastExecType      int        `json:"last_exec_type"`
	TaskType          int        `json:"task_type"`
	Rely              int        `json:"rely"`
	SubtasksId        string     `json:"subtasks_id"`
	Cron              string     `json:"cron"`
	TaskExecType      string     `json:"task_exec_type"`
	ExecTaskNodeType  int        `json:"exec_task_node_type"`
	ExecTaskNodeId    string     `json:"exec_task_node_id"`
	Cmd               string     `json:"cmd"`
	HttpType          string     `json:"http_type"`
	TaskFailNum       int        `json:"task_fail_num"`
	TaskFailRetryTime int        `json:"task_fail_retry_time"`
	TaskNotice        int        `json:"task_notice"`
	NoticeType        int        `json:"notice_type"`
	KeywordNotice     string     `json:"keyword_notice"`      // 提醒关键字
	Remake            string     `json:"remake"`              // 备注
	Status            int        `json:"status"`              // 状态
	NextExecTime      time.Time  `json:"next_exec_time"`      // 下次执行时间
	SubtasksData      []Task     `json:"subtasks_data"`       // 子任务数据
	ExecTaskNodeData  []TaskNode `json:"exec_task_node_data"` // 执行节点数据
}

任务

type TaskExecuteInfo

type TaskExecuteInfo struct {
	Task       *Task
	TheoryTime time.Time // 理论调度时间
	ActualTime time.Time // 实际调度时间
	CancelCtx  context.Context
	CancelFunc context.CancelFunc //  用于取消执行的cancel函数
}

任务执行状态

type TaskExecuteResult

type TaskExecuteResult struct {
	ExecuteInfo *TaskExecuteInfo
	Output      []byte    // 输出
	Err         error     // 错误信息
	StartTime   time.Time // 开始时间
	EndTime     time.Time // 结束时间
}

任务执行结果

type TaskLock

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

任务锁

func InitTaskLock

func InitTaskLock(task_id string, kv clientv3.KV, lease clientv3.Lease) (jobLock *TaskLock)

初始化一把锁

func (*TaskLock) TryLock

func (taskLock *TaskLock) TryLock() (err error)

尝试上锁

func (*TaskLock) Unlock

func (taskLock *TaskLock) Unlock()

释放锁

type TaskLog

type TaskLog struct {
	TaskId       int64     `json:"task_id"`        // 任务ID
	TaskName     string    `json:"task_name"`      // 任务名
	Cmd          string    `json:"cmd"`            // 执行命令
	Output       string    `json:"output"`         // 执行输出信息
	CreateTime   time.Time `json:"create_time"`    // 创建时间,也就是开始执行时间
	EndTime      time.Time `json:"end_time"`       // 执行结束时间
	Err          string    `json:"err"`            // 错误信息
	ConsumeTime  float32   `json:"consume_time"`   // 执行消耗时间,s为单位
	TaskExecType int       `json:"task_exec_type"` // 执行状态,1成功,0失败
	NodeIp       string    `json:"node_ip"`        // 节点IP
}

任务执行日志

type TaskLogSink

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

任务执行日志

var G_task_log_sink *TaskLogSink

func (*TaskLogSink) PushLog

func (taskLogSink *TaskLogSink) PushLog(task_log *TaskLog)

日志写入队列

type TaskLogWaitBucket

type TaskLogWaitBucket struct {
	Logs []interface{}
}

待写入的日志数据

type TaskManager

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

任务管理

var G_task_manager *TaskManager

func (*TaskManager) WatchTaskKill

func (taskManager *TaskManager) WatchTaskKill()

监听任务强杀

func (*TaskManager) WatchTaskList

func (taskManager *TaskManager) WatchTaskList()

监听任务列表

func (*TaskManager) WatchTaskStop

func (taskManager *TaskManager) WatchTaskStop()

监听任务停止

type TaskNode

type TaskNode struct {
	Id         int64     `json:"id"`
	Ip         string    `json:"ip"`
	CreateTime time.Time `json:"create_time"`
	Remake     string    `json:"remake"`
	IsDelete   int       `json:"is_delete"` // 0删除,1正常
}

节点

type TaskSchedulePlan

type TaskSchedulePlan struct {
	Task     *Task
	Expr     *cronexpr.Expression // cron对象
	NextTime time.Time            // 下次执行时间
	TaskLock *TaskLock
}

任务调度

Jump to

Keyboard shortcuts

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