sched

package
v0.0.0-...-1327151 Latest Latest
Warning

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

Go to latest
Published: Apr 13, 2020 License: BSD-3-Clause Imports: 4 Imported by: 0

Documentation

Overview

Package sched provides methods of scheduling tasks.

Index

Constants

View Source
const (
	PriorityMax    float64 = 1
	PriorityHigh   float64 = 0.9
	PriorityNormal float64 = 0
	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 this many proposed tasks
}

Request for work.

type Scheduler

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

Scheduler proposes work.

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 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