schedule

package module
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Nov 29, 2023 License: MIT Imports: 8 Imported by: 0

README

otter-batch

定时任务

Documentation

Index

Constants

View Source
const (
	ActionRun      = baseApi + "/run"  // 启动任务
	ActionKill     = baseApi + "/kill" // 终止任务
	ActionLog      = baseApi + "/log"  // 任务日志
	ActionBeat     = baseApi + "/log"  // 心跳检测
	ActionIdleBeat = baseApi + "/log"  // 忙碌检测
)
View Source
const (
	Success = 200
	Error   = 500
)

Variables

This section is empty.

Functions

func Init

func Init(opts ...Option) (err error)

Types

type CallElement

type CallElement struct {
	HandleCode int    `json:"handleCode"` //200表示正常,500表示失败
	HandleMsg  string `json:"handleMsg"`
}

CallElement 执行器执行完任务后,回调任务结果时使用

func Callback

func Callback(code int, msg string) CallElement

type Job

type Job interface {
	Run() // 任务执行
}

type Option

type Option func(s *schedule)

func WithTask

func WithTask(rt ...RegTask) Option

WithTask 任务ID、处理函数、cron表达式

type RegTask

type RegTask struct {
	Handler  string
	CronSpec string
	Func     TaskFunc
}

type RunReq

type RunReq struct {
	JobID           int64  `json:"jobId"`           // 任务ID
	ExecutorHandler string `json:"executorHandler"` // 任务标识
}

RunReq 触发任务请求参数

type Schedule

type Schedule interface {
	AddJob(executorHandler string, spec string, f TaskFunc) (err error)
	RunJob(jobId string) CallElement
}
var Server Schedule

Server 全局调度器

type Task

type Task struct {
	Id    string
	Name  string
	Param *RunReq

	StartTime int64
	EndTime   int64
	// contains filtered or unexported fields
}

Task 任务

func (*Task) Run

func (t *Task) Run() CallElement

Run 运行任务

type TaskFunc

type TaskFunc func() (code int, msg string)

TaskFunc 任务执行函数

Jump to

Keyboard shortcuts

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