service

package
v0.70.0 Latest Latest
Warning

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

Go to latest
Published: Feb 20, 2023 License: MIT Imports: 8 Imported by: 0

Documentation

Overview

Package service 服务管理

Index

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 Func

type Func func(context.Context) error

func (Func) Serve added in v0.70.0

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

type Job added in v0.55.0

type Job = scheduled.Job

type JobFunc added in v0.55.0

type JobFunc = scheduled.JobFunc

type Scheduler added in v0.55.0

type Scheduler = scheduled.Scheduler

type Server added in v0.55.0

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

func NewServer added in v0.70.0

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

func (*Server) Add added in v0.55.0

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

func (*Server) AddAt added in v0.55.0

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

func (*Server) AddCron added in v0.55.0

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

func (*Server) AddFunc added in v0.70.0

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

func (*Server) AddJob added in v0.55.0

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

func (*Server) AddTicker added in v0.55.0

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

func (*Server) Jobs added in v0.55.0

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

func (*Server) Run added in v0.55.0

func (srv *Server) Run()

func (*Server) Services added in v0.55.0

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

func (*Server) Stop added in v0.55.0

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

func (srv *Service) State() State

State 服务状态

func (*Service) Title

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

Title 服务名称

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
}

type State

type State = scheduled.State

Jump to

Keyboard shortcuts

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