service

package
v0.59.1 Latest Latest
Warning

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

Go to latest
Published: Sep 26, 2022 License: MIT Imports: 7 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 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 InternalNewServer added in v0.55.0

func InternalNewServer(loc *base.Base) *Server

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

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

AddAt 添加新的定时任务

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

func (*Server) AddCron added in v0.55.0

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

AddCron 添加新的定时任务

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

func (*Server) AddJob added in v0.55.0

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

AddJob 添加新的计划任务

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

func (*Server) AddTicker added in v0.55.0

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

AddTicker 添加新的定时任务

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

func (*Server) Jobs added in v0.55.0

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

Jobs 返回所有的计划任务

func (*Server) Run added in v0.55.0

func (srv *Server) Run()

func (*Server) Running added in v0.55.0

func (srv *Server) Running() bool

func (*Server) Services added in v0.55.0

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

Services 返回长期运行的服务函数列表

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

func (srv *Service) Run()

Run 开始执行该服务

func (*Service) State

func (srv *Service) State() State

State 服务状态

func (*Service) Stop

func (srv *Service) Stop()

func (*Service) Title

func (srv *Service) Title() string

Title 服务名称

type ServiceFunc added in v0.55.0

type ServiceFunc func(ctx context.Context) error

ServiceFunc 服务实际需要执行的函数

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

type State

type State = scheduled.State

State 服务的状态值

Jump to

Keyboard shortcuts

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