service

package
v0.69.0 Latest Latest
Warning

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

Go to latest
Published: Feb 13, 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 Func added in v0.66.0

type Func func(context.Context) error

func (Func) Serve added in v0.66.0

func (f Func) Serve(ctx context.Context) error

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 Servicer)

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) AddFunc added in v0.66.0

func (srv *Server) AddFunc(title localeutil.LocaleStringer, f func(context.Context) error)

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) Title

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

Title 服务名称

type Servicer added in v0.66.0

type Servicer interface {
	// Serve 运行服务
	//
	// 这是个阻塞方法,实现者需要正确处理 [context.Context.Done] 事件。
	// 如果是通过 [context.Context] 的相关操作取消的,应该返回 [context.Context.Err]。
	Serve(context.Context) error
}

Servicer 长期运行的服务需要实现的接口

Jump to

Keyboard shortcuts

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