cron

package module
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Oct 27, 2020 License: Apache-2.0 Imports: 6 Imported by: 1

README

cron

golang stand-alone cron

Documentation

Overview

Example (Cron)
c := New()
c.addFunc("*", func() {
	fmt.Println("111111")
})

c.addFunc("*", func() {
	fmt.Println("222222")
})

c.Start()
Output:

111
Example (Info)
c := New()
c.Info("schedule", "now", time.Now(), "entry", "1", "next", "2")
c.Error(errors.New("无此权限"), "schedule", "now", time.Now(), "entry", "1", "next", "2")
Output:

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Cron

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

Cron struct

func New

func New() *Cron

New returns a new Cron job runner, modified by the given options

func (*Cron) AddFunc

func (c *Cron) AddFunc(spec string, f func()) (TaskID, error)

func (*Cron) AddJob

func (c *Cron) AddJob(spec string, job Job) (TaskID, error)

AddJob is The core method of adding Task entities

func (*Cron) Error

func (c *Cron) Error(err error, value ...interface{})

Error log

func (*Cron) Info

func (c *Cron) Info(value ...interface{})

Info log

func (*Cron) Schedule

func (c *Cron) Schedule(schedule Schedule, cmd Job) TaskID

Schedule add

func (*Cron) Start

func (c *Cron) Start()

Start the cron scheduler in its own goroutine, or no-op if already started.

type FuncJob

type FuncJob func()

func (FuncJob) Run

func (f FuncJob) Run()

type Job

type Job interface {
	Run()
}

Job is an interface for submitted cron jobs.

type LogFormatter

type LogFormatter func(Values ...interface{}) string

LogFormatter log格式化func

type Logger

type Logger interface {
	Info(values ...interface{})
	Error(err error, value ...interface{})
}

Logger is Log interface

var DefaultLogger Logger = PrintfLogger(os.Stdout, defaultFormat)

DefaultLogger 默认Logger

func PrintfLogger

func PrintfLogger(o io.Writer, f LogFormatter) Logger

type ParseOption

type ParseOption int

type Parser

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

func NewParser

func NewParser(options ParseOption) Parser

func (Parser) Parse

func (P Parser) Parse(spec string) (Schedule, error)

type PrintLogger

type PrintLogger struct {
	Format LogFormatter
	// contains filtered or unexported fields
}

PrintLogger ...

func (PrintLogger) Error

func (l PrintLogger) Error(err error, values ...interface{})

func (PrintLogger) Info

func (l PrintLogger) Info(values ...interface{})

type Schedule

type Schedule interface {
	// Next returns the next activation time, later than the given time.
	// Next is invoked initially, and then each time the job is run.
	Next(time.Time) time.Time
}

Schedule describes a job's duty cycle.

type ScheduleParser

type ScheduleParser interface {
	Parse(spec string) (Schedule, error)
}

ScheduleParser is Schedule Parser interface

type SpecSchedule

type SpecSchedule struct {
}

func (*SpecSchedule) Next

func (s *SpecSchedule) Next(t time.Time) time.Time

type Task

type Task struct {
	ID       TaskID
	Schedule Schedule
	Job      Job
	Next     time.Time
	Prev     time.Time
}

Task is entity

type TaskID

type TaskID int

TaskID is Task ID

Directories

Path Synopsis
example module

Jump to

Keyboard shortcuts

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