runner

package
v1.0.3 Latest Latest
Warning

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

Go to latest
Published: Feb 2, 2021 License: MIT Imports: 7 Imported by: 0

Documentation

Overview

* Package runner 用于按照顺序,执行程序任务操作,可作为cron作业或定时任务 runner 包可用于展示如何使用通道来监视程序的执行时间,如果程序运行时间太长,指定任务执行时间。 这个程序可能会作为 cron 作业执行,或者在基于定时任务的云环境(如 iron.io)里执行。 补充说明: 可能作为cron作业或基于定时任务,可以控制程序执行时间 使用通道来监控程序的执行时间,生命周期,甚至终止程序等。 我们这个程序叫runner,我们可以称之为执行者。 它可以在后台执行任何任务,而且我们还可以控制这个执行者,比如强制终止它等 此外这个执行者也是一个很不错的模式,比如我们写好之后,交给定时任务去执行即可 比如cron,这个模式我们还可以扩展更高效率的并发,更多灵活的控制程序的生命周期 更高效的监控等。

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrorTimeout = errors.New("task exec timeout")
	ErrInterrupt = errors.New("received interrupt signal")
)

Functions

This section is empty.

Types

type Logger

type Logger interface {
	Println(msg ...interface{})
}

Logger log interface

type Option

type Option func(r *Runner)

Option 采用func Option功能模式为Runner添加参数

func WithLogger

func WithLogger(l Logger) Option

WithLogger 设置r.logger打印日志的句柄

func WithTimeout

func WithTimeout(t time.Duration) Option

WithTimeout 设置任务超时时间

type Runner

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

Runner 声明一个runner

func New

func New(opts ...Option) *Runner

New 定义一个工厂函数创建runner 默认创建一个无超时任务的runner

func (*Runner) Add

func (r *Runner) Add(tasks ...func() error)

Add 将需要执行的任务添加到r.tasks队列中

func (*Runner) GetAllErrors

func (r *Runner) GetAllErrors() map[int]error

GetAllErrors 获取已经完成任务的error

func (*Runner) GetLastTaskId

func (r *Runner) GetLastTaskId() int

GetLastTaskId 获取最后一次完成任务id

func (*Runner) Start

func (r *Runner) Start() error

Start 开始执行所有的任务

Jump to

Keyboard shortcuts

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