service

package
v0.63.0 Latest Latest
Warning

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

Go to latest
Published: Jan 14, 2023 License: MIT Imports: 8 Imported by: 0

Documentation

Overview

Package service 服务管理

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Server

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

func NewServer

func NewServer(loc *time.Location, logs *logs.Logs) *Server

func (*Server) Add

func (srv *Server) Add(title localeutil.LocaleStringer, f ServiceFunc)

Add 添加新的服务

f 表示服务的运行函数; title 是对该服务的简要说明。

NOTE: 如果所有服务已经处于运行的状态,则会自动运行新添加的服务。

func (*Server) AddAt

func (srv *Server) AddAt(title string, f scheduled.JobFunc, ti time.Time, delay bool)

AddAt 添加新的定时任务

f 表示服务的运行函数; title 是对该服务的简要说明; t 指定的时间点; delay 是否在任务执行完之后,才计算下一次的执行时间点。

func (*Server) AddCron

func (srv *Server) AddCron(title string, f scheduled.JobFunc, spec string, delay bool)

AddCron 添加新的定时任务

f 表示服务的运行函数; title 是对该服务的简要说明; spec cron 表达式,支持秒; delay 是否在任务执行完之后,才计算下一次的执行时间点。

func (*Server) AddJob

func (srv *Server) AddJob(title string, f scheduled.JobFunc, scheduler scheduled.Scheduler, delay bool)

AddJob 添加新的计划任务

f 表示服务的运行函数; title 是对该服务的简要说明; scheduler 计划任务的时间调度算法实现; delay 是否在任务执行完之后,才计算下一次的执行时间点。

func (*Server) AddTicker

func (srv *Server) AddTicker(title string, f scheduled.JobFunc, dur time.Duration, imm, delay bool)

AddTicker 添加新的定时任务

f 表示服务的运行函数; title 是对该服务的简要说明; dur 时间间隔; imm 是否立即执行一次该任务; delay 是否在任务执行完之后,才计算下一次的执行时间点。

func (*Server) Jobs

func (srv *Server) Jobs() []*scheduled.Job

Jobs 返回所有的计划任务

func (*Server) Run

func (srv *Server) Run()

func (*Server) Running

func (srv *Server) Running() bool

func (*Server) Services

func (srv *Server) Services() []*Service

func (*Server) Stop

func (srv *Server) Stop()

Stop 停止所有服务

type Service

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

func (*Service) Err

func (srv *Service) Err() error

Err 上次的错误信息

不会清空该值。

func (*Service) Run

func (srv *Service) Run()

Run 开始执行该服务

func (*Service) State

func (srv *Service) State() scheduled.State

State 服务状态

func (*Service) Stop

func (srv *Service) Stop()

func (*Service) Title

func (srv *Service) Title(p *message.Printer) string

Title 服务名称

type ServiceFunc

type ServiceFunc func(ctx context.Context) error

ServiceFunc 服务函数的原型

实现者需要正确处理 ctx.Done 事件,调用者可能会主动取消函数执行; 如果是通 ctx.Done 取消的,应该返回 context.Canceled

Jump to

Keyboard shortcuts

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