service

package
v0.43.0 Latest Latest
Warning

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

Go to latest
Published: Oct 8, 2021 License: MIT Imports: 7 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

type Func func(ctx context.Context) error

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

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

type Manager

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

Manager 服务管理

func NewManager

func NewManager(logs *logs.Logs, loc *time.Location) *Manager

NewManager 返回 Manager

func (*Manager) AddAt added in v0.34.0

func (mgr *Manager) AddAt(title string, f scheduled.JobFunc, t time.Time, delay bool) error

AddAt 添加新的定时任务

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

func (*Manager) AddCron added in v0.34.0

func (mgr *Manager) AddCron(title string, f scheduled.JobFunc, spec string, delay bool) error

AddCron 添加新的定时任务

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

func (*Manager) AddJob added in v0.34.0

func (mgr *Manager) AddJob(title string, f scheduled.JobFunc, scheduler schedulers.Scheduler, delay bool)

AddJob 添加新的计划任务

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

func (*Manager) AddService

func (mgr *Manager) AddService(title string, f Func)

AddService 添加新的服务

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

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

func (*Manager) AddTicker added in v0.34.0

func (mgr *Manager) AddTicker(title string, f scheduled.JobFunc, dur time.Duration, imm, delay bool) error

AddTicker 添加新的定时任务

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

func (*Manager) Jobs added in v0.34.0

func (mgr *Manager) Jobs() []*scheduled.Job

Jobs 返回计划任务列表

func (*Manager) Run

func (mgr *Manager) Run()

Run 运行所有服务

func (*Manager) Services

func (mgr *Manager) Services() []*Service

Services 返回所有的服务列表

func (*Manager) Stop

func (mgr *Manager) Stop()

Stop 停止所有服务

type Service

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

Service 服务模型

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

Stop 停止服务

type State

type State int8

State 服务的状态值

const (
	Stopped State = iota // 当前处于停止状态,默认状态
	Running              // 正在运行
	Failed               // 出错,不再执行后续操作
)

几种可能的状态值

func (State) String

func (s State) String() string

Jump to

Keyboard shortcuts

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