crond

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Jun 21, 2017 License: MIT Imports: 16 Imported by: 0

Documentation

Index

Constants

View Source
const (
	StateRunning = "running"
	StateSuccess = "success"
	StateFail    = "failed"

	TypeCron = "cron"
	TypeOnce = "once"
)

Variables

View Source
var (
	RunningCount int32 = 0
)

Functions

func AddNotifyAddr

func AddNotifyAddr(addr string)

func Count

func Count() int

func Init

func Init(localIP string)

func NotifyAddrs

func NotifyAddrs() []string

func Once

func Once(job *Job) string

func ParseIPFromID

func ParseIPFromID(id string) (string, error)

func RawOnce

func RawOnce(name string, args FuncArg) (string, error)

func Register

func Register(name string, f Func) error

func RemoveNotifyAddr

func RemoveNotifyAddr(addr string)

func Sleep

func Sleep(ID string, sleep bool)

func Start

func Start()

func Status

func Status() string

func Stop

func Stop()

func Update

func Update(jobs []Job, version string) error

func Version

func Version() string

Types

type Crond

type Crond struct {
	Version string
	// contains filtered or unexported fields
}

func New

func New() *Crond

func (*Crond) Count

func (cd *Crond) Count() int

func (*Crond) Entries

func (cd *Crond) Entries(query map[string]string) []EntrySpec

func (*Crond) Find

func (cd *Crond) Find(name string, args FuncArg) (*Job, error)

func (*Crond) FindById

func (cd *Crond) FindById(id string) (*Job, error)

func (*Crond) Once

func (cd *Crond) Once(job *Job) string

func (*Crond) RawOnce

func (cd *Crond) RawOnce(name string, args FuncArg) (string, error)

func (*Crond) Register

func (cd *Crond) Register(name string, f Func) error

func (*Crond) Sleep

func (cd *Crond) Sleep(ID string, sleep bool)

func (*Crond) Start

func (cd *Crond) Start()

start scheduler

func (*Crond) Stop

func (cd *Crond) Stop()

stop scheduler

func (*Crond) Update

func (cd *Crond) Update(jobs []Job, version string) error

update the job list

func (*Crond) WrapFunc

func (cd *Crond) WrapFunc(job *Job, rid string) func()

TODO job record should be persistent, and support search

type EntrySpec

type EntrySpec struct {
	Prev time.Time `json:"prev"`
	Next time.Time `json:"next"`
	J    Job       `json:"job"`
}

func Entries

func Entries(query map[string]string) []EntrySpec

type Func

type Func func(FuncArg) (FuncResult, error)

Cron task's func type and arg type and result type

type FuncArg

type FuncArg map[string]interface{}

func (FuncArg) GetInt

func (fa FuncArg) GetInt(key string, defaultv int) int

func (FuncArg) GetString

func (fa FuncArg) GetString(key string, defaultv string) string

func (FuncArg) GetStringSlice

func (fa FuncArg) GetStringSlice(key string, defaultv []string) []string

type FuncResult

type FuncResult map[string]interface{}

type Job

type Job struct {
	ID     string  `json:"id"`
	Spec   string  `json:"spec"`   // string like "0 0 * * *"
	Action string  `json:"action"` // task's name
	Args   FuncArg `json:"args"`
	Type   JobType `json:"type"` // cronJob or onceJob
	Sleep  bool    `json:"sleep"`
	// contains filtered or unexported fields
}

func Find

func Find(name string, args FuncArg) (*Job, error)

func FindById

func FindById(id string) (*Job, error)

func (*Job) GenerateID

func (job *Job) GenerateID(ip string) string

func (*Job) Match

func (job *Job) Match(query map[string]string) bool

type JobRecord

type JobRecord struct {
	Job
	RecordID string     `json:"rid"`
	Result   FuncResult `json:"result"`
	State    JobState   `json:"state"`
	Start    time.Time  `json:"start"`
	End      time.Time  `json:"end"`
	Reason   string     `json:"reason"`
}

func (*JobRecord) Match

func (record *JobRecord) Match(query map[string]string) bool

func (*JobRecord) Value

func (record *JobRecord) Value() interface{}

type JobState

type JobState string

type JobType

type JobType string

Jump to

Keyboard shortcuts

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