Documentation ¶
Index ¶
- Constants
- type DownGradeStrategy
- type GiveUpNotImportantStrategy
- type GiveUpStrategy
- type LimitLoad
- type LongScheduleStrategy
- type OnceScheduleStrategy
- type ReBalanceStrategy
- type RunNoJobStrategy
- type ScheduleOption
- func WithHighLoadJudgeStrategy(io internal.IsOutlier) ScheduleOption
- func WithLimitLoadDownGradeStrategy(threshold int64, st GiveUpStrategy) ScheduleOption
- func WithLoadBalancePreemptStrategy() ScheduleOption
- func WithLongScheduleStrategy() ScheduleOption
- func WithMaxConcurrentPreemptNum(num int) ScheduleOption
- func WithRefreshInterval(interval time.Duration) ScheduleOption
- func WithStrictReBalanceStrategy() ScheduleOption
- func WithTimeoutInterval(interval time.Duration) ScheduleOption
- type ScheduleStrategy
- type ScheduleStrategyType
- type Scheduler
- func (s *Scheduler) AddJob(ctx context.Context, name string, timeout time.Duration, cron string, ...) error
- func (s *Scheduler) AddLoad(delta int64)
- func (s *Scheduler) GetLoad() int64
- func (s *Scheduler) JobWrapper(f func(ctx context.Context) error) executor.Func
- func (s *Scheduler) Refresh(ctx context.Context, j domain.Job) error
- func (s *Scheduler) RefreshSelf(ctx context.Context) error
- func (s *Scheduler) RegisterExecutor(exec executor.Executor)
- func (s *Scheduler) RegisterJobFunc(name string, f func(context.Context) error)
- func (s *Scheduler) RemoveRunningJob(id int64)
- func (s *Scheduler) Run(ctx context.Context)
- func (s *Scheduler) Schedule(ctx context.Context) error
- func (s *Scheduler) ScheduleJob(ctx context.Context, j domain.Job)
- func (s *Scheduler) SetDownGrade(dg bool)
- func (s *Scheduler) SubLoad(delta int64)
- type SchedulerConfig
Constants ¶
View Source
const ( TimeoutPreemptType string = "timeout" LoadBalancerPreemptType string = "loadbalancer" )
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type DownGradeStrategy ¶
type DownGradeStrategy interface { // Do 降级来时进行job的释放 Do(scr *Scheduler) }
DownGradeStrategy 业务高峰期时的策略
func NewLimitLoad ¶
func NewLimitLoad(g GiveUpStrategy, threshold int64) DownGradeStrategy
NewLimitLoad 非负载均衡也能用
func NewRunNoJobStrategy ¶
func NewRunNoJobStrategy() DownGradeStrategy
type GiveUpNotImportantStrategy ¶
type GiveUpNotImportantStrategy struct { }
func (GiveUpNotImportantStrategy) Do ¶
func (g GiveUpNotImportantStrategy) Do()
type GiveUpStrategy ¶
type GiveUpStrategy string
const ( LowWeightFirst GiveUpStrategy = "lowWeight" HighWeightFirst GiveUpStrategy = "highWeight" )
type LimitLoad ¶
type LimitLoad struct { GiveUpStrategy Threshold int64 }
type LongScheduleStrategy ¶
type LongScheduleStrategy struct { }
LongScheduleStrategy 长期抢占,抢到了任务就不释放,除非自身续约失败/负载较高被其它实例剥夺任务
type OnceScheduleStrategy ¶
type OnceScheduleStrategy struct { }
OnceScheduleStrategy 抢到了任务只执行一次,执行完之后就释放任务
type ReBalanceStrategy ¶
type ReBalanceStrategy string
const ( RelaxReBalanceStrategy ReBalanceStrategy = ReBalanceStrategy(internal.RelaxReBalance) StrictReBalanceStrategy = ReBalanceStrategy(internal.StrictReBalance) )
type RunNoJobStrategy ¶
type RunNoJobStrategy struct { }
func (RunNoJobStrategy) Do ¶
func (r RunNoJobStrategy) Do(scr *Scheduler)
type ScheduleOption ¶
type ScheduleOption struct { Idx int F func(*SchedulerConfig) }
func WithHighLoadJudgeStrategy ¶
func WithHighLoadJudgeStrategy(io internal.IsOutlier) ScheduleOption
func WithLimitLoadDownGradeStrategy ¶
func WithLimitLoadDownGradeStrategy(threshold int64, st GiveUpStrategy) ScheduleOption
func WithLoadBalancePreemptStrategy ¶
func WithLoadBalancePreemptStrategy() ScheduleOption
func WithLongScheduleStrategy ¶
func WithLongScheduleStrategy() ScheduleOption
func WithMaxConcurrentPreemptNum ¶
func WithMaxConcurrentPreemptNum(num int) ScheduleOption
func WithRefreshInterval ¶
func WithRefreshInterval(interval time.Duration) ScheduleOption
func WithStrictReBalanceStrategy ¶
func WithStrictReBalanceStrategy() ScheduleOption
func WithTimeoutInterval ¶
func WithTimeoutInterval(interval time.Duration) ScheduleOption
type ScheduleStrategy ¶
func NewLongScheduleStrategy ¶
func NewLongScheduleStrategy() ScheduleStrategy
func NewOnceScheduleStrategy ¶
func NewOnceScheduleStrategy() ScheduleStrategy
type ScheduleStrategyType ¶
type ScheduleStrategyType string
const ( LongScheduleType ScheduleStrategyType = "long" OnceScheduleType ScheduleStrategyType = "once" )
type Scheduler ¶
type Scheduler struct { Name string ScheduleSg ScheduleStrategy PreemptSg internal.PreemptStrategy DownGradeSg DownGradeStrategy //负载数值, 抢到job了就增加job对应的负载,释放的时候减少负载,也可以用户自己设定负载 Load int64 RefreshInterval time.Duration RunningJobs *sync.Map Threshold int64 DownGrade bool // contains filtered or unexported fields }
Scheduler 调度器
func NewScheduler ¶
func NewScheduler(db *gorm.DB, opts ...ScheduleOption) *Scheduler
func (*Scheduler) JobWrapper ¶
func (*Scheduler) RegisterExecutor ¶
func (*Scheduler) RegisterJobFunc ¶
func (*Scheduler) RemoveRunningJob ¶
func (*Scheduler) SetDownGrade ¶
type SchedulerConfig ¶
type SchedulerConfig struct { DB *gorm.DB //续约任务的时间间隔,RefreshInterval要略小于TimeoutInterval RefreshInterval time.Duration //如果一个在running的任务超过TimeoutInterval没有人续约,则认为这个任务续约失败,可以被剥夺 TimeoutInterval time.Duration //抢占的最多的任务并发数,如果抢占了超过MaxConcurrentPreemptNum数量的任务,调度器会阻塞, //直到所占有的任务数量小于MaxConcurrentPreemptNum才会继续抢占 MaxConcurrentPreemptNum int //调度策略;分为长期抢占的循环调度,和单次调度,默认为单次调度 ScheduleSg ScheduleStrategy // 抢占策略:分为负载均衡抢占策略和普通抢占策略;负载均衡策略:执行任务时,如果自身处于高负载状态且有低负载候选者, // 会把任务让出去,让低负载的候选者抢占;两种策略均有续约和抢占机制 PreemptSg internal.PreemptStrategy // 降级下的执行策略:全部让出任务/保留部分的任务(限制总负载)/保留白名单任务 DownGradeSg DownGradeStrategy // 负载再均衡策略,宽松策略和严苛策略,默认为宽松策略 ReBalanceSg ReBalanceStrategy //降级情况下,限制的负载总和最大值,未指定默认为0 Threshold int64 //判断负载过高的离群点的方法 IsOutlier internal.IsOutlier Logger logx.Logger }
Source Files ¶
Click to show internal directories.
Click to hide internal directories.