sched

package
v0.0.0-...-c9cfaf6 Latest Latest
Warning

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

Go to latest
Published: Jun 5, 2020 License: BSD-3-Clause Imports: 4 Imported by: 1

Documentation

Overview

Package sched provides methods of scheduling tasks.

Index

Constants

View Source
const (
	PriorityMax     float64 = 1
	PriorityHighest float64 = 0.9
	PriorityHigh    float64 = 0.5
	PriorityNormal  float64 = 0
	PriorityLow     float64 = -0.5
	PriorityIdle    float64 = -0.9
	PriorityMin     float64 = -1
)

Suggested priority values.

Variables

This section is empty.

Functions

This section is empty.

Types

type Request

type Request struct {
	Worker string // worker to request for
	Num    int    // request at least this many proposed tasks
}

Request for work.

type Scheduler

type Scheduler interface {
	Tasks(ctx context.Context, req *Request) ([]*Task, error)
}

Scheduler proposes work.

func CompositeScheduler

func CompositeScheduler(schedulers ...Scheduler) Scheduler

CompositeScheduler merges proposed tasks from multiple schedulers.

func NewDefault

func NewDefault(d *db.DB) Scheduler

NewDefault builds a scheduler with sensible defaults.

func NewRecentCommits

func NewRecentCommits(d *db.DB, pri TimePriority) Scheduler

NewRecentCommits builds a scheduler that proposes tasks for recent comments and modules with no completed tasks in the database. Priority is computed with the commit time and supplied priority function.

func NewRetry

func NewRetry(d *db.DB, maxErrors int, cooloff time.Duration) Scheduler

NewRetry builds a scheduler that retries previous error tasks, for which there has never been a successful completion. The scheduler will stop suggestiing retries after maxErrors total errors for a commit module pair. Retries will only be scheduled after the given cooloff period.

func SingleTaskScheduler

func SingleTaskScheduler(task *Task) Scheduler

SingleTaskScheduler always returns the given task.

func StaticScheduler

func StaticScheduler(tasks []*Task) Scheduler

StaticScheduler always returns the same tasks.

type SchedulerFunc

type SchedulerFunc func(ctx context.Context, req *Request) ([]*Task, error)

SchedulerFunc adapts a function to the Scheduler interface.

func (SchedulerFunc) Tasks

func (f SchedulerFunc) Tasks(ctx context.Context, req *Request) ([]*Task, error)

Tasks calls f.

type Task

type Task struct {
	Priority float64
	Spec     entity.TaskSpec
}

Task is prioritized work proposed by a scheduler.

func NewTask

func NewTask(pri float64, s entity.TaskSpec) *Task

NewTask builds a task with the supplied priority and specifiction.

type TasksByPriority

type TasksByPriority []*Task

TasksByPriority provides a sort.Interface for sorting tasks in increasing priority.

func (TasksByPriority) Len

func (t TasksByPriority) Len() int

func (TasksByPriority) Less

func (t TasksByPriority) Less(i, j int) bool

func (TasksByPriority) Swap

func (t TasksByPriority) Swap(i, j int)

type TimePriority

type TimePriority func(time.Time) float64

TimePriority is a method of determining priority based on a time.

func ConstantTimePriority

func ConstantTimePriority(p float64) TimePriority

ConstantTimePriority returns a function that returns p for all times.

func TimeSinceSmoothStep

func TimeSinceSmoothStep(d0 time.Duration, p0 float64, d1 time.Duration, p1 float64) TimePriority

TimeSinceSmoothStep has priority p0 for times up to d0 from now, priority p1 for times over d1 from now and smoothly transitions between the two.

Jump to

Keyboard shortcuts

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