litejob

package module
v0.0.0-...-df03910 Latest Latest
Warning

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

Go to latest
Published: Apr 14, 2016 License: GPL-3.0 Imports: 11 Imported by: 0

README

LiteJob

A Fast & Safely Golang Task Dispatch.

Features

  • more storage engine support

    1. Redis(storage job list with redis list)
    2. Sqlite(storage job list with a table)
    3. Memory(storage job list with a memory map)
    4. Mysql ... others
  • plugin easy

Examples

see source/examples

RoadMap

  1. support Redis,Sqlite,Memory storage
  2. support Http And Rpc

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Guid

func Guid() string

func RegisterStorage

func RegisterStorage(name string, storage StorageInitFunc)

Types

type Dispatch

type Dispatch struct {
	sync.Mutex

	Count uint32
	// contains filtered or unexported fields
}

func NewDispatch

func NewDispatch(configure *DispatchConfigure) (*Dispatch, error)

func (*Dispatch) JobNew

func (this *Dispatch) JobNew(name string, param interface{}) (*Job, error)

func (*Dispatch) JobState

func (this *Dispatch) JobState(jobId string) (*JobState, error)

func (*Dispatch) Loop

func (this *Dispatch) Loop()

func (*Dispatch) RegisterHandler

func (this *Dispatch) RegisterHandler(name string, handler JobHandler)

func (*Dispatch) Start

func (this *Dispatch) Start()

type DispatchConfigure

type DispatchConfigure struct {
	Engine          string               // storage engine name.eg:(redis,sqlite,memory)
	MaxConcurrency  uint32               // max concurrency goroutine
	MaxReplyCount   uint32               // max reply job to job list when job ask need again
	HeartInterval   time.Duration        // sleep some time when empty job list
	DumpInterval    time.Duration        // not used
	Logfile         string               // log file path
	EngineConfigure EngineConfigure      // engine configure
	Callback        JobCallbackConfigure // job callbacks
}

configure dispatch

type DispatchStatus

type DispatchStatus struct {
	Running uint32 //runing goroutine count
	Len     uint32 //job list length
}

dispatch engine status for monitor

type EngineConfigure

type EngineConfigure map[string]interface{}

func (*EngineConfigure) Get

func (this *EngineConfigure) Get(name string, defaultVal interface{}) interface{}

type Job

type Job struct {
	Id         string      //任务id,使用/dev/urandom 获取
	Name       string      //任务名称,调度器注册的任务名称
	Param      interface{} //任务参数
	CreateTime time.Time   //任务创建时间
	FlushTime  time.Time   //任务结束时间
	Status     JobStatus   //任务状态
	ReplyCount uint32      //重试次数
}

任务 todo 优先队列的支持

func (*Job) MarshalBinary

func (this *Job) MarshalBinary() ([]byte, error)

func (*Job) UnmarshalBinary

func (this *Job) UnmarshalBinary(data []byte) error

type JobCallback

type JobCallback func(job *Job)

任务回调函数定义

type JobCallbackConfigure

type JobCallbackConfigure struct {
	After  JobCallback
	Before JobCallback
}

type JobHandler

type JobHandler func(job *Job) JobReturn

任务函数定义

type JobReturn

type JobReturn struct {
	Status JobStatus //任务状态
	Msg    string    //任务执行结果
}

任务函数返回信息

type JobState

type JobState struct {
	JobId      string
	Name       string
	Status     string
	Msg        string
	RunTime    int
	WaitTime   int
	ReplyCount int
}

func (*JobState) MarshalBinary

func (this *JobState) MarshalBinary() ([]byte, error)

func (*JobState) UnmarshalBinary

func (this *JobState) UnmarshalBinary(data []byte) error

type JobStatus

type JobStatus uint

任务状态

const (
	JobStatusWating  JobStatus = 1 //任务已经添加成功,等待执行
	JobStatusDoing   JobStatus = 2 //任务正在执行
	JobStatusFailed  JobStatus = 3 //任务执行失败
	JobStatusSuccess JobStatus = 4 //任务执行成功
	JobStatusAgain   JobStatus = 5 //任务重新执行,受限于max_reply
	JobStatusKill    JobStatus = 100
	JobStatusUnknow  JobStatus = 101
)

func (JobStatus) String

func (this JobStatus) String() string

type Log

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

func NewLog

func NewLog(path string) *Log

func (*Log) Error

func (this *Log) Error(format string, v ...interface{})

func (*Log) Normal

func (this *Log) Normal(format string, v ...interface{})

type Storage

type Storage interface {
	JobPush(job *Job) error
	JobPop() (*Job, error)
	JobFlush() error
	JobLen() uint32
	JobStateUpdate(state *JobState) error
	JobState(jobId string) (*JobState, error)
}

func GetStorage

func GetStorage(name string, configure *DispatchConfigure) (Storage, error)

type StorageInitFunc

type StorageInitFunc func(configure *DispatchConfigure) Storage

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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