Documentation ¶
Overview ¶
Package service 服务管理
Index ¶
- Constants
- type Job
- type JobFunc
- type Scheduler
- type Server
- func (srv *Server) Add(title string, f ServiceFunc)
- func (srv *Server) AddAt(title string, f JobFunc, ti time.Time, delay bool)
- func (srv *Server) AddCron(title string, f JobFunc, spec string, delay bool)
- func (srv *Server) AddJob(title string, f JobFunc, scheduler Scheduler, delay bool)
- func (srv *Server) AddTicker(title string, f JobFunc, dur time.Duration, imm, delay bool)
- func (srv *Server) Jobs() []*Job
- func (srv *Server) Run()
- func (srv *Server) Running() bool
- func (srv *Server) Services() []*Service
- func (srv *Server) Stop()
- type Service
- type ServiceFunc
- type State
Constants ¶
View Source
const ( Stopped = scheduled.Stopped // 当前处于停止状态,默认状态 Running = scheduled.Running // 正在运行 Failed = scheduled.Failed // 出错,不再执行后续操作 )
几种可能的状态值
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Server ¶ added in v0.55.0
type Server struct {
// contains filtered or unexported fields
}
func InternalNewServer ¶ added in v0.55.0
InternalNewServer 声明服务管理对象 Server
func (*Server) Add ¶ added in v0.55.0
func (srv *Server) Add(title string, f ServiceFunc)
Add 添加新的服务
f 表示服务的运行函数; title 是对该服务的简要说明。
NOTE: 如果所有服务已经处于运行的状态,则会自动运行新添加的服务。
func (*Server) AddAt ¶ added in v0.55.0
AddAt 添加新的定时任务
f 表示服务的运行函数; title 是对该服务的简要说明; t 指定的时间点; delay 是否在任务执行完之后,才计算下一次的执行时间点。
func (*Server) AddCron ¶ added in v0.55.0
AddCron 添加新的定时任务
f 表示服务的运行函数; title 是对该服务的简要说明; spec cron 表达式,支持秒; delay 是否在任务执行完之后,才计算下一次的执行时间点。
func (*Server) AddJob ¶ added in v0.55.0
AddJob 添加新的计划任务
f 表示服务的运行函数; title 是对该服务的简要说明; scheduler 计划任务的时间调度算法实现; delay 是否在任务执行完之后,才计算下一次的执行时间点。
func (*Server) AddTicker ¶ added in v0.55.0
AddTicker 添加新的定时任务
f 表示服务的运行函数; title 是对该服务的简要说明; dur 时间间隔; imm 是否立即执行一次该任务; delay 是否在任务执行完之后,才计算下一次的执行时间点。
type ServiceFunc ¶ added in v0.55.0
ServiceFunc 服务实际需要执行的函数
实现者需要正确处理 ctx.Done 事件,调用者可能会主动取消函数执行; 如果是通 ctx.Done 取消的,应该返回 context.Canceled。
Click to show internal directories.
Click to hide internal directories.