timepolicy

package
v0.0.0-...-693abe4 Latest Latest
Warning

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

Go to latest
Published: Nov 16, 2019 License: MIT Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Engine

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

Engine will run process the policy and run the function at a right time

func NewEngine

func NewEngine(ctx context.Context) *Engine

NewEngine create a engine

func (*Engine) Clear

func (engine *Engine) Clear()

Clear all the jobs

func (*Engine) Register

func (engine *Engine) Register(policy string, job Job) error

Register a policy to engine with using time.Now() as from time

func (*Engine) RegisterWithTime

func (engine *Engine) RegisterWithTime(from time.Time, policy string, job Job) error

RegisterWithTime a policy to engine

type Job

type Job interface {
	Do(time.Time)
	Finished() bool
}

Job represents the job type which the engine will call it by go Func()

type Policy

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

Policy represent a group of policy item

func ParsePolicy

func ParsePolicy(from time.Time, s string) (Policy, error)

ParsePolicy 解析策略字符串

func ParsePolicyBytes

func ParsePolicyBytes(from time.Time, s []byte) (Policy, error)

ParsePolicyBytes 解析策略数组

func (*Policy) NextTime

func (policy *Policy) NextTime(now int64) int64

NextTime 返回下一次执行策略的时间, 基于参数 now 计算

Jump to

Keyboard shortcuts

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