core

package
v0.0.0-...-3e9cf14 Latest Latest
Warning

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

Go to latest
Published: Jun 1, 2017 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func InitPersistence

func InitPersistence(redisHost string)

Types

type Job

type Job interface {
	Run() error
	String() string
	Unmarshal([]byte) error   // 反序列化
	Marshal() ([]byte, error) // 序列化
	Unique() []byte           // 必须返回一个[]byte,将做为唯一标示,相同唯一标示的job会替换已存在的job
}

type JobModel

type JobModel struct {
	Id          string `orm:"col(id)" json:"id"`
	RunTime     int64  `orm:"col(run_time)" json:"run_time"`
	Data        string `orm:"col(data)" json:"data"`
	SuccessTime int64  `orm:"col(success_time)" json:"success_time"`
	FailTime    int64  `orm:"col(fail_time)" json:"fail_time"`
	Error       string `orm:"col(error)" json:"error"`
	// contains filtered or unexported fields
}

job mysql 结构体 用于保存成功失败记录

type JobWrap

type JobWrap struct {
	IdDb  string // 入库的ID,唯一标识
	Deep  int64  // 圈数,一圈1小时
	Count int    // 第几次运行

	RunTime int64 // 运行时间戳,只在持久化时入库出库使用
	// contains filtered or unexported fields
}

包裹JOB

func (*JobWrap) Marshal

func (p *JobWrap) Marshal() (data []byte, err error)

func (*JobWrap) Unmarshal

func (p *JobWrap) Unmarshal(data []byte) (err error)

type NewJobFunc

type NewJobFunc func() Job

type Scheduler

type Scheduler struct {
	Tasks     [3600]*Task `json:"tasks"`      // 3600个task 每一秒需要执行一个
	CurrIndex int32       `json:"curr_index"` // 当前正在执行哪个task

	sync.Mutex // 锁全部Task
	// contains filtered or unexported fields
}

func NewScheduler

func NewScheduler(c *SchedulerConfig, newJobFunc NewJobFunc) *Scheduler

func (*Scheduler) AddJob

func (p *Scheduler) AddJob(duration int64, job Job)

秒为单位

func (*Scheduler) DeleteJob

func (p *Scheduler) DeleteJob(job Job) (ok bool)

删除所有相同job

func (*Scheduler) DeleteThenAddJob

func (p *Scheduler) DeleteThenAddJob(duration int64, job Job) (deleted bool)

删除所有相同的job后添加一个新job

func (*Scheduler) GetCurrJobWraps

func (p *Scheduler) GetCurrJobWraps() *[]*JobWrap

func (*Scheduler) Info

func (p *Scheduler) Info() string

func (*Scheduler) LoadFormRedis

func (p *Scheduler) LoadFormRedis() (err error)

从db装入job

func (*Scheduler) Work

func (p *Scheduler) Work()

开启工作循环

type SchedulerConfig

type SchedulerConfig struct {
	ServerHttp  string `json:"server_http"`
	Persistence bool   `json:"persistence"` // 是否使用redis持久化
	Redis       string `json:"redis"`       // redis
	Log         bool   `json:"log"`         // 是否记录日志
	MysqlLink   string `json:"mysql"`       // mysql
	Retry       []int  `json:"retry"`       // 重试延时
}

type Task

type Task struct {
	JobWraps   []*JobWrap // 当前task里的任务
	sync.Mutex            // 锁一个Task
}

Jump to

Keyboard shortcuts

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