Documentation
¶
Overview ¶
Package service 服务管理
Index ¶
- Constants
- type Func
- type Job
- type JobFunc
- type Scheduler
- type Server
- func (srv *Server) Add(title localeutil.LocaleStringer, f Servicer)
- 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) AddFunc(title localeutil.LocaleStringer, f func(context.Context) error)
- 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) Services() []*Service
- func (srv *Server) Stop()
- type Service
- type Servicer
- type Services
- 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 (*Server) Add ¶ added in v0.55.0
func (srv *Server) Add(title localeutil.LocaleStringer, f Servicer)
func (*Server) AddFunc ¶ added in v0.70.0
func (srv *Server) AddFunc(title localeutil.LocaleStringer, f func(context.Context) error)
type Servicer ¶ added in v0.70.0
type Servicer interface { // Serve 运行服务 // // 这是个阻塞方法,实现者需要正确处理 [context.Context.Done] 事件。 // 如果是通过 [context.Context] 的相关操作取消的,应该返回 [context.Context.Err]。 Serve(context.Context) error }
Servicer 长期运行的服务需要实现的接口
type Services ¶ added in v0.70.0
type Services interface { // AddCron 添加新的定时任务 // // f 表示服务的运行函数; // title 是对该服务的简要说明; // spec cron 表达式,支持秒; // delay 是否在任务执行完之后,才计算下一次的执行时间点。 AddCron(title string, f JobFunc, spec string, delay bool) // AddTicker 添加新的定时任务 // // f 表示服务的运行函数; // title 是对该服务的简要说明; // dur 时间间隔; // imm 是否立即执行一次该任务; // delay 是否在任务执行完之后,才计算下一次的执行时间点。 AddTicker(title string, f JobFunc, dur time.Duration, imm, delay bool) // AddAt 添加新的定时任务 // // f 表示服务的运行函数; // title 是对该服务的简要说明; // t 指定的时间点; // delay 是否在任务执行完之后,才计算下一次的执行时间点。 AddAt(title string, f JobFunc, ti time.Time, delay bool) // AddJob 添加新的计划任务 // // f 表示服务的运行函数; // title 是对该服务的简要说明; // scheduler 计划任务的时间调度算法实现; // delay 是否在任务执行完之后,才计算下一次的执行时间点。 AddJob(title string, f JobFunc, scheduler Scheduler, delay bool) // Add 添加新的服务 // // f 表示服务的运行函数; // title 是对该服务的简要说明。 // // NOTE: 如果服务已经处于运行的状态,则会自动运行新添加的服务。 Add(title localeutil.LocaleStringer, f Servicer) // 添加新的服务 AddFunc(title localeutil.LocaleStringer, f func(context.Context) error) // 获取所有的服务列表 Services() []*Service // Jobs 返回所有的计划任务 Jobs() []*Job }
Click to show internal directories.
Click to hide internal directories.