Documentation ¶
Index ¶
- Constants
- Variables
- type Dcron
- func (d *Dcron) AddFunc(jobName, cronStr string, cmd func()) (err error)
- func (d *Dcron) AddJob(jobName, cronStr string, job Job) (err error)
- func (d *Dcron) GetJob(jobName string, thisNodeOnly bool) (*JobWarpper, error)
- func (d *Dcron) GetJobs(thisNodeOnly bool) []*JobWarpper
- func (d *Dcron) GetLogger() dlog.Logger
- func (d *Dcron) NodeID() string
- func (d *Dcron) Remove(jobName string)
- func (d *Dcron) Run()
- func (d *Dcron) SetLogger(logger dlog.Logger)
- func (d *Dcron) Start()
- func (d *Dcron) Stop()
- type INodePool
- type IRecentJobPacker
- type Job
- type JobWarpper
- type JobWithTime
- type JobWithTimeHeap
- func (jobHeap *JobWithTimeHeap) Index(i int) interface{}
- func (jobHeap *JobWithTimeHeap) Len() int
- func (jobHeap *JobWithTimeHeap) Less(i, j int) bool
- func (jobHeap *JobWithTimeHeap) Pop() (ret interface{})
- func (jobHeap *JobWithTimeHeap) Push(x interface{})
- func (jobHeap *JobWithTimeHeap) Swap(i, j int)
- type NodePool
- type Option
- func CronOptionChain(wrappers ...cron.JobWrapper) Option
- func CronOptionLocation(loc *time.Location) Option
- func CronOptionParser(p cron.ScheduleParser) Option
- func CronOptionSeconds() Option
- func RunningLocally() Option
- func WithClusterStable(timeWindow time.Duration) Option
- func WithHashReplicas(d int) Option
- func WithLogger(logger dlog.Logger) Option
- func WithNodeUpdateDuration(d time.Duration) Option
- func WithRecoverFunc(recoverFunc RecoverFuncType) Option
- type RecentJobPacker
- type RecoverFuncType
- type StableJob
Constants ¶
const ( NodePoolStateSteady = "NodePoolStateSteady" NodePoolStateUpgrade = "NodePoolStateUpgrade" )
Variables ¶
var ( ErrJobExist = errors.New("jobName already exist") ErrJobNotExist = errors.New("jobName not exist") ErrJobWrongNode = errors.New("job is not running in this node") )
var (
ErrNodePoolIsUpgrading = errors.New("nodePool is upgrading")
)
Functions ¶
This section is empty.
Types ¶
type Dcron ¶
type Dcron struct { ServerName string RecoverFunc RecoverFuncType // contains filtered or unexported fields }
Dcron is main struct
func NewDcronWithOption ¶
NewDcronWithOption create a Dcron with Dcron Option
func (*Dcron) GetJob ¶ added in v0.5.5
func (d *Dcron) GetJob(jobName string, thisNodeOnly bool) (*JobWarpper, error)
Get job by jobName if this jobName not exist, will return error.
if `thisNodeOnly` is true if this job is not available in this node, will return error. otherwise return the struct of JobWarpper whose name is jobName.
func (*Dcron) GetJobs ¶ added in v0.5.5
func (d *Dcron) GetJobs(thisNodeOnly bool) []*JobWarpper
Get job list.
if `thisNodeOnly` is true return all jobs available in this node. otherwise return all jobs added to dcron.
we never return nil. If there is no job. this func will return an empty slice.
type INodePool ¶ added in v0.5.0
type IRecentJobPacker ¶ added in v0.5.1
type IRecentJobPacker interface { // goroutine safety. // Add a job to packer // will save recent jobs (like 2 * heartbeat duration) AddJob(jobName string, t time.Time) error // goroutine safety. // Pop out all jobs in packer PopAllJobs() (jobNames []string) }
IRecentJobPacker this is an interface which be used to pack the jobs running in the cluster state is `unstable`. like some nodes broken or new nodes were add.
func NewRecentJobPacker ¶ added in v0.5.1
func NewRecentJobPacker(timeWindow time.Duration) IRecentJobPacker
type JobWarpper ¶
JobWarpper is a job warpper
func (JobWarpper) Execute ¶ added in v0.5.1
func (job JobWarpper) Execute()
type JobWithTime ¶ added in v0.5.1
type JobWithTimeHeap ¶ added in v0.5.1
type JobWithTimeHeap []JobWithTime
func (*JobWithTimeHeap) Index ¶ added in v0.5.1
func (jobHeap *JobWithTimeHeap) Index(i int) interface{}
func (*JobWithTimeHeap) Len ¶ added in v0.5.1
func (jobHeap *JobWithTimeHeap) Len() int
func (*JobWithTimeHeap) Less ¶ added in v0.5.1
func (jobHeap *JobWithTimeHeap) Less(i, j int) bool
func (*JobWithTimeHeap) Pop ¶ added in v0.5.1
func (jobHeap *JobWithTimeHeap) Pop() (ret interface{})
func (*JobWithTimeHeap) Push ¶ added in v0.5.1
func (jobHeap *JobWithTimeHeap) Push(x interface{})
func (*JobWithTimeHeap) Swap ¶ added in v0.5.1
func (jobHeap *JobWithTimeHeap) Swap(i, j int)
type NodePool ¶
type NodePool struct {
// contains filtered or unexported fields
}
NodePool For cluster steable. NodePool has 2 states:
- Steady If this nodePoolLists is the same as the last update, we will mark this node's state to Steady. In this state, this node can run jobs.
- Upgrade If this nodePoolLists is different to the last update, we will mark this node's state to Upgrade. In this state, this node can not run jobs.
func (*NodePool) CheckJobAvailable ¶ added in v0.5.0
Check if this job can be run in this node.
func (*NodePool) GetLastNodesUpdateTime ¶ added in v0.5.1
type Option ¶
type Option func(*Dcron)
Option is Dcron Option
func CronOptionChain ¶
func CronOptionChain(wrappers ...cron.JobWrapper) Option
CronOptionChain is Warp cron with chain
func CronOptionLocation ¶
CronOptionLocation is warp cron with location
func CronOptionParser ¶
func CronOptionParser(p cron.ScheduleParser) Option
CronOptionParser is warp cron with schedules.
func CronOptionSeconds ¶
func CronOptionSeconds() Option
CronOptionSeconds is warp cron with seconds
func RunningLocally ¶ added in v0.5.5
func RunningLocally() Option
func WithClusterStable ¶ added in v0.5.1
You can use this option to start the recent jobs rerun after the cluster upgrading.
func WithLogger ¶
WithLogger both set dcron and cron logger.
func WithNodeUpdateDuration ¶
WithNodeUpdateDuration set node update duration
func WithRecoverFunc ¶ added in v0.5.0
func WithRecoverFunc(recoverFunc RecoverFuncType) Option
You can defined yourself recover function to make the job will be added to your dcron when the process restart
type RecentJobPacker ¶ added in v0.5.1
func (*RecentJobPacker) AddJob ¶ added in v0.5.1
func (rjp *RecentJobPacker) AddJob(jobName string, t time.Time) (err error)
func (*RecentJobPacker) PopAllJobs ¶ added in v0.5.1
func (rjp *RecentJobPacker) PopAllJobs() (jobNames []string)
type RecoverFuncType ¶ added in v0.5.0
type RecoverFuncType func(d *Dcron)